String Title = Request.Form["title"];
String Info_Sort = Request.Form["Info_Sort"];
String Author = Request.Form["Author"];
String ShowTime = Request.Form["ShowTime"];
String Content = Request.Form["FCK_Content"]; SqlConnection DbConn = db.Open();
String StrSQL = "Select * From WebInfo";
SqlDataAdapter thisAdapter = new SqlDataAdapter(StrSQL,DbConn);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "WebInfo");
DataRow thisRow = thisDataSet.Tables["WebInfo"].NewRow(); thisRow["Title"] = Title;
thisRow["Info_Sort"] = Info_Sort;
thisRow["Author"] = Author;
thisRow["ShowTime"] = ShowTime;
thisRow["Content"] = Content; thisDataSet.Tables["WebInfo"].Rows.Add(thisRow);
thisAdapter.Update(thisDataSet, "WebInfo");我用 上面的方法 将数据保存至数据库 一共保存 了五列数据 但数据库表中 还有一些字段 没出现在 上面 用 select 语句直接去数据库中查询 出现 那些 建有 default约束的字段全都为 null 并没有 出现 default(...)中的默认值但我又不想 "Select title,Info_Sort,Author,ShowTime,Content From WebInfo" 指定要保存的数据
应该如何解决这个问题啊
String Info_Sort = Request.Form["Info_Sort"];
String Author = Request.Form["Author"];
String ShowTime = Request.Form["ShowTime"];
String Content = Request.Form["FCK_Content"]; SqlConnection DbConn = db.Open();
String StrSQL = "Select * From WebInfo";
SqlDataAdapter thisAdapter = new SqlDataAdapter(StrSQL,DbConn);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "WebInfo");
DataRow thisRow = thisDataSet.Tables["WebInfo"].NewRow(); thisRow["Title"] = Title;
thisRow["Info_Sort"] = Info_Sort;
thisRow["Author"] = Author;
thisRow["ShowTime"] = ShowTime;
thisRow["Content"] = Content; thisDataSet.Tables["WebInfo"].Rows.Add(thisRow);
thisAdapter.Update(thisDataSet, "WebInfo");我用 上面的方法 将数据保存至数据库 一共保存 了五列数据 但数据库表中 还有一些字段 没出现在 上面 用 select 语句直接去数据库中查询 出现 那些 建有 default约束的字段全都为 null 并没有 出现 default(...)中的默认值但我又不想 "Select title,Info_Sort,Author,ShowTime,Content From WebInfo" 指定要保存的数据
应该如何解决这个问题啊
String StrSQL = "Select title,Info_Sort,Author,ShowTime,Content From WebInfo"
就是这两句如果写第一句 那么 插入的数据 就算没指定字段
thisRow["Title"] = Title;
thisRow["Info_Sort"] = Info_Sort;
thisRow["Author"] = Author;
thisRow["ShowTime"] = ShowTime;
thisRow["Content"] = Content;
就指定五个字段 其余没指定的全都在数据库里为空 包括 有 df约束的
但是 如果 用第二句 那 数据库中 有 df约束的 就不会为空了