How can I easily view the contents of a datatable or dataview in the immediate window

后端 未结 8 1570
情书的邮戳
情书的邮戳 2020-12-04 13:02

Sometimes I will be at a breakpoint in my code and I want to view the contents of a DataTable variable (or a DataTable in a DataSet).

8条回答
  •  Happy的楠姐
    2020-12-04 13:47

    i have programmed a small method for it.. its a generalize function..

        public static void printDataTable(DataTable tbl)
        {
            string line = "";
            foreach (DataColumn item in tbl.Columns)
            {
                line += item.ColumnName +"   ";
            }
            line += "\n";
            foreach (DataRow row in tbl.Rows)
            {
                for (int i = 0; i < tbl.Columns.Count; i++)
                {
                    line += row[i].ToString() + "   ";
                }
                line += "\n";
            }
            Console.WriteLine(line) ;
        }
    

提交回复
热议问题