首页 > 代码库 > C# 向DataTable中插入数据或伪造DataTable
C# 向DataTable中插入数据或伪造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# 向DataTable中插入数据或伪造DataTable
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。