//1.
DataTable dt = new DataTable();
dt.Columns.add( "ID "), typeof(int));
dt.Columns.add( "Test "), typeof(string));
//2.
DataSet ds = new DataSet();
DataTable dt = new DataTable("Task");
dt.Columns.Add("A");
dt.Columns.Add("B");
dt.Columns.Add("C");
dt.Columns.Add("D");
DataRow dr = dt.NewRow();
dr["A"] = "Task";
dr["B"] = "Go To No."
dr["C"] = "3Days";
dr["D"] = "C1,C2,C3,C2";
//实例:
DataSet ds = new DataSet();
DataTable dd = new DataTable("Task");
dd.Columns.Add("Sextype");
dd.Columns.Add("SexId");
DataRow rs = dd.NewRow();
rs["Sextype"] = "男";
rs["SexId"] = 1;
dd.Rows.InsertAt(rs, 0);
DataRow rw = dd.NewRow();
rw["Sextype"] = "女";
rw["SexId"] = 2;
dd.Rows.InsertAt(rw, 1);
cmbSex.DisplayMember = "sextype";
cmbSex.ValueMember = "SexId";
cmbSex.DataSource = dd;
|