写法一:
var dt = new DataTable();
dt.Columns.Add(new DataColumn("Id", System.Type.GetType("System.Int32")));
dt.Columns.Add(new DataColumn("Username", System.Type.GetType("System.String")));
DataRow dr = null;
dr = dt.NewRow();
dr["Id"] = 123;
dr["Username"] = "name";
dt.Rows.Add(dr);
}
return dt;
写法二:
DataTable bandTable = new DataTable();//绑定grid,新建的表结构
DataColumn column1 = new DataColumn("Id", typeof(int));
DataColumn column2 = new DataColumn("Username", typeof(string));
bandTable.Columns.Add(column1);
bandTable.Columns.Add(column2);
DataRow rowAll = null;
rowAll = bandTable.NewRow();
rowAll[0] = 123;
rowAll[1] = "name";
bandTable.Rows.Add(rowAll);
return bandTable;