在不能更新数据库的内容啊,帮忙看看.谢谢
我先把数据库的内容显示出来,然后再更改,可为什么改了后数据库的内容不变啊,
程序是
void Page_Load(Object sender, EventArgs e)
{
OleDbConnection condatabase;
OleDbCommand cmddatabase;
OleDbDataReader dtrdatabase;
string strname;
string strSelect;
strname = Request.QueryString[ "name1 "];
// Retrieve records from database
condatabase = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\\WebSite2\\database.mdb ");
strSelect = "Select * from rigist Where 姓名=@name1 ";
cmddatabase = new OleDbCommand(strSelect, condatabase);
cmddatabase.Parameters.Add( "@name1 ", strname);
condatabase.Open();
dtrdatabase = cmddatabase.ExecuteReader(CommandBehavior.SingleRow);
if (dtrdatabase.Read())
{
TextBox1.Text = dtrdatabase[ "姓名 "].ToString();
TextBox2.Text = dtrdatabase[ "住宅电话 "].ToString();
TextBox3.Text = dtrdatabase[ "职务 "].ToString();
TextBox4.Text = dtrdatabase[ "邮政编码 "].ToString();
TextBox5.Text = dtrdatabase[ "密码 "].ToString();
TextBox6.Text = dtrdatabase[ "简介 "].ToString();
}
dtrdatabase.Close();
condatabase.Close();
}
void Button_Click(Object sender, EventArgs e)
{
OleDbConnection condatabase;
OleDbCommand cmddatabase;
string strUpdate;
OleDbCommand cmdUpdate;
condatabase = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\\WebSite2\\database.mdb ");
strUpdate = "Update rigist Set 姓名=@name,住宅电话=@phone,职务=@handset,邮政编码=@post,密码=@psd,简介=@text1 Where 姓名=@name1 ";
cmdUpdate = new OleDbCommand( strUpdate, condatabase);
cmdUpdate.Parameters.Add( "@name1 ", TextBox1.Text);
cmdUpdate.Parameters.Add( "@phone ", TextBox2.Text );
cmdUpdate.Parameters.Add( "@handset ", TextBox3.Text );
cmdUpdate.Parameters.Add( "@post ", TextBox4.Text );
cmdUpdate.Parameters.Add( "@psd ", TextBox5.Text );
cmdUpdate.Parameters.Add( "@text1 ", TextBox6.Text );
condatabase.Open();
cmdUpdate.ExecuteNonQuery();
if ((int)cmdUpdate.ExecuteNonQuery() > 0)
{
Response.Redirect( "success.aspx ");
}
else
{
//失败
}
condatabase.Close();
}
</script>
[解决办法]
当你单击按钮时,触发page_load,然后再将这条记录的内容,返回到所有的textbox中,再更新时,还是将原来的值写入了.
据我所知,access库,应当使用?而不是@