C#編程完成DataTable添加行的辦法。本站提示廣大學習愛好者:(C#編程完成DataTable添加行的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#編程完成DataTable添加行的辦法正文
本文實例講述了C#編程完成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;// 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" });
願望本文所述對年夜家C#法式設計有所贊助。