码迷,mamicode.com
首页 > 其他好文 > 详细

构建DataTable

时间:2019-07-10 11:11:30      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:div   datarow   rom   style   span   stat   成本   GridView   adt   

 

【博客原因】数据一直来自于数据库,造成本地构建Datatable 当做数据源不会了,特此记录一下

 

 

 

DataTable dt = new DataTable();
//构建列
dt.Columns.Add(new DataColumn("id"));
dt.Columns.Add(new DataColumn("ServerID"));
dt.Columns.Add(new DataColumn("SN"));
dt.Columns.Add(new DataColumn("city"));
dt.Columns.Add(new DataColumn("cur_name"));
dt.Columns.Add(new DataColumn("RoadType"));
dt.Columns.Add(new DataColumn("visitRange"));
dt.Columns.Add(new DataColumn("lastDate"));
dt.Columns.Add(new DataColumn("bstationName"));
dt.Columns.Add(new DataColumn("setupnum"));
dt.Columns.Add(new DataColumn("setupattach"));
dt.Columns.Add(new DataColumn("purchasefrom"));
dt.Columns.Add(new DataColumn("setupNo"));
dt.Columns.Add(new DataColumn("purchasewarrant"));
dt.Columns.Add(new DataColumn("statename"));
dt.Columns.Add(new DataColumn("stationID"));
dt.Columns.Add(new DataColumn("outModel"));
dt.Columns.Add(new DataColumn("inmodel")); 
循环遍历,添加数据
for (int i = 0; i < 100; i++) { DataRow dr1 = dt.NewRow(); dr1["id"] = "1708"; dr1["ServerID"] = "11111111111111111"; dr1["SN"] = "BVPABYA003913-1"; dr1["city"] = "福州市"; dr1["cur_name"] = "测试"; dr1["Roade"] = "邮件"; dr1["visit"] = "正常上门"; dr1["lastDate"] = "2011-12-06"; dr1["bstationName"] = "总部"; dr1["setu"] = ""; dr1["serattach"] = ""; dr1["chase"] = "其他"; dr1["setNo"] = ""; dr1["purcha"] = "其他"; dr1["StateName"] = "已分派"; dr1["StationID"] = "000000"; dr1["outModel"] = "LC32H03K"; dr1["model"] = "E312AGKNDW3A6NNX"; //将构建好的行加进DataTable中 dt.Rows.Add(dr1); } GridView1.DataSource = DT; GridView1.DataBind();

 

构建DataTable

标签:div   datarow   rom   style   span   stat   成本   GridView   adt   

原文地址:https://www.cnblogs.com/whatarey/p/11161964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!