我的数据库为MySql原来的写法:
MyCommand = new MySqlCommand("update inform set inf_title='"+txttitle.Text+"',inf_code='"+txtcode.Text+"',inf_content='"+FreeTextBox1.Text+"' where inf_id=" + Int32.Parse(Request.QueryString["infid"]),DBConn);改后的写法:
MyCommand = new MySqlCommand("update inform set inf_title=@title,inf_code=@code,inf_content=@content where inf_id=@id",DBConn);
MyCommand.Parameters.Add("@title",txttitle.Text);
MyCommand.Parameters.Add("@code",txtcode.Text);
MyCommand.Parameters.Add("@content",FreeTextBox1.Text);
MyCommand.Parameters.Add("@id",Int32.Parse(Request.QueryString["infid"]));改前的运行正常,改后运行不出错,但更新没效果,改不了东西了,这是怎么回事?
如果把改后的改成:
MyCommand = new MySqlCommand("update inform set inf_title=@title,inf_code=@code,inf_content=@content where inf_id=" + Int32.Parse(Request.QueryString["infid"]),DBConn); MyCommand.Parameters.Add("@title",txttitle.Text);
MyCommand.Parameters.Add("@code",txtcode.Text);
MyCommand.Parameters.Add("@content",FreeTextBox1.Text);
MyCommand.Parameters.Add("@id",Int32.Parse(Request.QueryString["infid"]));那么一按提交修改就会把所有的字段都替换成空,请高手指点!!