现有代码如下:
//创建学生信息表
DataSet ds = new DataSet();
DataTable dt = new DataTable("StudentInfo");
DataColumn col = new DataColumn("Stud_Number",typeof(int));
col.AllowDBNull = false;
col.AutoIncrement = true;
col.AutoIncrementSeed = 1;
col.AutoIncrementStep = 1;
dt.Columns.Add(col);col = new DataColumn("Stud_Name",typeof(string));
col.AllowDBNull = false;
col.MaxLength = 10;dt.Columns.Add(col);col = new DataColumn("Stud_Sex",typeof(string));
col.AllowDBNull = false;
col.MaxLength = 2;
col.DefaultValue = "男";dt.Columns.Add(col);col = new DataColumn("Stud_Age",typeof(int));
col.AllowDBNull = true;
dt.Columns.Add(col);
dt.PrimaryKey = new DataColumn[]{dt.Columns["Stud_Number"]};ds.Tables.Add(dt);我如何把上面自己编写的表格更新到数据库中去,也就是说,如何在数据库中生成上面编写的表格。
急啊!100分。请教!
//创建学生信息表
DataSet ds = new DataSet();
DataTable dt = new DataTable("StudentInfo");
DataColumn col = new DataColumn("Stud_Number",typeof(int));
col.AllowDBNull = false;
col.AutoIncrement = true;
col.AutoIncrementSeed = 1;
col.AutoIncrementStep = 1;
dt.Columns.Add(col);col = new DataColumn("Stud_Name",typeof(string));
col.AllowDBNull = false;
col.MaxLength = 10;dt.Columns.Add(col);col = new DataColumn("Stud_Sex",typeof(string));
col.AllowDBNull = false;
col.MaxLength = 2;
col.DefaultValue = "男";dt.Columns.Add(col);col = new DataColumn("Stud_Age",typeof(int));
col.AllowDBNull = true;
dt.Columns.Add(col);
dt.PrimaryKey = new DataColumn[]{dt.Columns["Stud_Number"]};ds.Tables.Add(dt);我如何把上面自己编写的表格更新到数据库中去,也就是说,如何在数据库中生成上面编写的表格。
急啊!100分。请教!
如果要存整个表的话,你可以用把表格加到DATASET.用DATASET生成XML文件.要不,你就只能通过获得HTML代码.
da.UpdateCommand =CreateUpdateCommand();//自己写的
da.InsertCommand =CreateInsertCommand();();//自己写的
da.DeleteCommand =CreateDeleteCommand();();//自己写的
da.Update(myDataTable);//更新,这样做就是效率不高的,哈哈