C#编码创造一个DataSet

DataSet ds = new DataSet("tb");
DataTable dt = new DataTable();
ds.Tables.Add(dt);
DataColumn dc = new DataColumn();
dc.ColumnName = "id";
dc.DataType = typeof(int);

DataColumn dc1 = new DataColumn();
dc1.ColumnName = "name";
dc1.DataType = typeof(string);
dt.Columns.Add(dc);
dt.Columns.Add(dc1);
dt.PrimaryKey = new DataColumn[] { dc };
DataRow dr = dt.NewRow();
dr[0] = 1;
dr[1] = "zhangsan";
DataRow dr1 = dt.NewRow();
dr1[0] = 2;
dr1[1] = "lisi";
dt.Rows.Add(dr);
dt.Rows.Add(dr1);

你可能感兴趣的:(Data)