易采站长站为您分析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);
方法二:










