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

DataTable添加行的方法

时间:2017-05-09 18:56:01      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:null   table   dbnull   方法   add   seed   rip   auto   desc   

方法一:

DataTable  tblDatas = new DataTable("Datas");
DataColumn dc = null;
dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
dc.AutoIncrement = true;//自动增加
dc.AutoIncrementSeed = 1;//起始为1
dc.AutoIncrementStep = 1;//步长为1
dc.AllowDBNull = false;//

dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));

DataRow newRow;
newRow = tblDatas.NewRow();
newRow["Product"] = "水果刀";
newRow["Version"] = "2.0";
newRow["Description"] = "打架专用";
tblDatas.Rows.Add(newRow);

newRow = tblDatas.NewRow();
newRow["Product"] = "折叠凳";
newRow["Version"] = "3.0";
newRow["Description"] = "行走江湖七武器之一";
tblDatas.Rows.Add(newRow);

方法二:

 DataTable tblDatas = new DataTable("Datas");
tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
tblDatas.Columns[0].AutoIncrement = true;
tblDatas.Columns[0].AutoIncrementSeed = 1;
tblDatas.Columns[0].AutoIncrementStep = 1;

tblDatas.Columns.Add("Product", Type.GetType("System.String"));
tblDatas.Columns.Add("Version", Type.GetType("System.String"));
tblDatas.Columns.Add("Description", Type.GetType("System.String"));

tblDatas.Rows.Add(new object[]{null,"a","b","c"});
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });

DataTable添加行的方法

标签:null   table   dbnull   方法   add   seed   rip   auto   desc   

原文地址:http://www.cnblogs.com/soundcode/p/6832039.html

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