DataTableはよく使う操作です。
4559 ワード
列と行を追加する3つの方法(転載)原文の住所:http://www.cnblogs.com/jRoger/articles/1887581.html
dt 2.Rows.Add(rowNew.ItemAray);DataTable Rowを追加する方法
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);
dt 2.Rows.Add(rowNew.ItemAray);DataTable Rowを追加する方法