如何为DATATABLE添加多行(转贴)

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

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

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

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

DataRow newRow;

newRow = tblDatas.NewRow();

newRow["Product"] = "ddf";

newRow["Version"] = "fgfg";

newRow["Description"] = "fgfg";

tblDatas.Rows.Add(newRow);

newRow = tblDatas.NewRow();

newRow["Product"] = "gffg";

newRow["Version"] = "gffg";

newRow["Description"] = "gfg";

tblDatas.Rows.Add(newRow);

原文地址:https://www.cnblogs.com/sarahVSEve/p/3364964.html