c#手写datatable
DataTable dataTable1 = new DataTable(); dataTable1.Columns.Add("列名"); dataTable1.Columns.Add("23"); DataRow dr1 = dataTable1.NewRow(); dr1["列名"] = "列名"; dr1["23"] = "23"; dataTable1.Rows.Add(dr1); for (int i = 0; i < 5; i++) { DataRow dr = dataTable1.NewRow(); dr["列名"] = "sf"; dr["23"] = "34"; dataTable1.Rows.Add(dr); }
//输出测试 foreach (DataRow row in dataTable1.Rows) { for (int i = 0; i < dataTable1.Columns.Count; i++) { Console.Write(row[i] + " "); } Console.WriteLine(); } Console.ReadKey();