首页 > 技术文章 > DataTable常用操作

wangjunwei 2015-05-27 15:46 原文

添加列和行的三种方法(转载) 原文地址:http://www.cnblogs.com/jRoger/articles/1887581.html

 

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); 

 

dt2.Rows.Add(rowNew.ItemArray);//DataTable添加Row的方法

 

DataTable添加列和行的三种方法

 

推荐阅读