C#后台定义一个DataTable并手动写入静态数据(测试数据)

//创建一个DataTable,并为之添加数据(自定义DataTable)

DataTable dtz = new DataTable();

//添加Table中的列
DataColumn dc1 = new DataColumn("pn", Type.GetType("System.String"));
DataColumn dc2 = new DataColumn("DESCR", Type.GetType("System.String"));
DataColumn dc3 = new DataColumn("SN", Type.GetType("System.String"));
DataColumn dc4 = new DataColumn("BIN", Type.GetType("System.String"));
DataColumn dc5 = new DataColumn("QTY", Type.GetType("System.String"));
DataColumn dc6 = new DataColumn("TRANS_QTY", Type.GetType("System.String"));
dtz.Columns.Add(dc1);
dtz.Columns.Add(dc2);
dtz.Columns.Add(dc3);
dtz.Columns.Add(dc4);
dtz.Columns.Add(dc5);
dtz.Columns.Add(dc6);


//以上代码完成了DataTable的构架,但是里面是没有任何数据的

for (int i = 0; i < 50; i++)
{
DataRow dr = dtz.NewRow();
dr["pn"] = "010106-101";
dr["DESCR"] = "PCA, PII/100,512K,TSUNAMI";
dr["SN"] = "PCA";
dr["BIN"] = "010106-101";
dr["QTY"] = "010106-101";
dr["TRANS_QTY"] = "010106-101";
dtz.Rows.Add(dr);
}

//自动填充了50条相同的记录进去

//将创建好的DataTable(手动添加的列和静态数据正常赋给GridView使用)

//DataTable dt = dtz;
//DetailList.DataSource = dt;
//DetailList.DataBind();

posted @ 2020-08-24 11:45  墨染暖栀  阅读(522)  评论(0编辑  收藏  举报
/* 看板娘 */ /* 粒子吸附*/