using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; namespace _14._13数据集DataSet { class Program { static void Main(string[] args) { //创建DataSet对象 DataSet myds = new DataSet("csharp51zxw"); DataTable mydt = new DataTable("mytable001"); myds.Tables.Add(mydt); DataColumn myDataColumn1 = new DataColumn("id", Type.GetType("System.Int32")); DataColumn myDataColumn2 = new DataColumn("name", Type.GetType("System.String")); DataColumn myDataColumn3 = new DataColumn("department", Type.GetType("System.String")); mydt.Columns.Add(myDataColumn1); mydt.Columns.Add(myDataColumn2); mydt.Columns.Add(myDataColumn3); string[,] mystr= { { "张三","开发部"}, { "李四", "销售部" }, { "王五", "技术支持部" }, { "赵六", "人力资源部" } }; for(int i = 0; i < mystr.Length / 2; i++) { DataRow myRow = mydt.NewRow(); myRow[0] = i; myRow["name"] = mystr[i, 0]; myRow[2] = mystr[i, 1]; mydt.Rows.Add(myRow); } myds.AcceptChanges(); Console.WriteLine("更改前的数据"); } } }
记录学习路上的点点滴滴