dataset更新数据库问题
为什么这样不能完成数据库的更新呢?请高手相助!protectedvoidPage_Load(objectsender,EventArgse){if(!Page.IsPos...
为什么这样不能完成数据库的更新呢?请高手相助!
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
id = Request.QueryString["Notice_ID"].ToString();
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/mydb.mdb") + ";User Id=;Password=;");
sql = "select contentn,addtime,author,Notice_ID from tab_Notice;";
conn.Open();
ds = new DataSet();
da = new OleDbDataAdapter(sql, conn);
cb = new OleDbCommandBuilder(da);
da.Fill(ds,"notice");
conn.Close();
dt=ds.Tables["notice"];
dt.PrimaryKey = new DataColumn[]{dt.Columns["Notice_ID"]};
drow = dt.Rows.Find(id);
txtC.Text = drow.ItemArray[0].ToString();
txtDT.Text = drow.ItemArray[1].ToString();
txtAT.Text = drow.ItemArray[2].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string dtime = txtDT.Text.Trim();
string au = txtAT.Text.Trim();
string cont = txtC.Text.Trim();
conn.Open();
da.UpdateCommand = cb.GetUpdateCommand();
drow["contentn"] = cont;
drow["author"] = au;
drow["addtime"] = dtime;
ds.AcceptChanges();
da.Update(ds,"notice");
Response.Write("done");
conn.Close();
//Response.Write(cont);
} 展开
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
id = Request.QueryString["Notice_ID"].ToString();
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/mydb.mdb") + ";User Id=;Password=;");
sql = "select contentn,addtime,author,Notice_ID from tab_Notice;";
conn.Open();
ds = new DataSet();
da = new OleDbDataAdapter(sql, conn);
cb = new OleDbCommandBuilder(da);
da.Fill(ds,"notice");
conn.Close();
dt=ds.Tables["notice"];
dt.PrimaryKey = new DataColumn[]{dt.Columns["Notice_ID"]};
drow = dt.Rows.Find(id);
txtC.Text = drow.ItemArray[0].ToString();
txtDT.Text = drow.ItemArray[1].ToString();
txtAT.Text = drow.ItemArray[2].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string dtime = txtDT.Text.Trim();
string au = txtAT.Text.Trim();
string cont = txtC.Text.Trim();
conn.Open();
da.UpdateCommand = cb.GetUpdateCommand();
drow["contentn"] = cont;
drow["author"] = au;
drow["addtime"] = dtime;
ds.AcceptChanges();
da.Update(ds,"notice");
Response.Write("done");
conn.Close();
//Response.Write(cont);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询