1 public System.Data.DataTable getDataTable() 2 { 3 System.Data.DataTable dt = new System.Data.DataTable(); 4 dt.Columns.Add(new DataColumn("username", typeof(string))); 5 dt.Columns.Add(new DataColumn("userid", typeof(string))); 6 dt.Columns.Add(new DataColumn("createtime", typeof(string))); 7 8 using (BXSEntities BX = new BXSEntities()) 9 { 10 List<users> users = BX.users.Select(u => u).ToList(); 11 12 foreach (var item in users) 13 { 14 DataRow row = dt.NewRow(); 15 row[0] = item.userName; 16 row[1] = item.userID; 17 row[2] = item.createTime; 18 dt.Rows.Add(row); 19 } 20 } 21 return dt; 22 }
原文:http://www.cnblogs.com/zhaomengmeng/p/4992556.html