日期:2014-05-18 浏览次数:20516 次
string updatacmd = "update g_user set name='" + txt_name.Text + "',card='" + txt_card.Text + "',riqi='" + txt_money.Text + "',gtel='" + txt_gtel.Text + "',tel='" + txt_tel.Text + "',email='" + txt_email.Text + "',youbian='" + txt_youbian.Text + "',address='" + txt_add.Text + "',sex='" + txt_sex.Text + "',danbaoren='" + txt_danbaoren.Text + "', job='" + txt_joy.Text + "' where id='" + txt_serch.Text + "'";
public bool getupdata()
{
bool flag = false;
SqlConnection conn = null;
dbcon db = new dbcon();
string updatacmd = "update g_user set name='" + txt_name.Text + "',card='" + txt_card.Text + "',riqi='" + txt_money.Text + "',gtel='" + txt_gtel.Text + "',tel='" + txt_tel.Text + "',email='" + txt_email.Text + "',youbian='" + txt_youbian.Text + "',address='" + txt_add.Text + "',sex='" + txt_sex.Text + "',danbaoren='" + txt_danbaoren.Text + "', job='" + txt_joy.Text + "' where id='" + txt_serch.Text + "'";
try
{
conn = db.getcon();
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = updatacmd;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
return true;
}
catch { return false;}
finally{
conn.Close();
}
return flag;
}
protected void btn_tj_Click(object sender, EventArgs e)
{
if (getupdata())
{
Response.Write("<script>alert('修改成功!')</script>");
Response.Redirect("admin_.aspx");
}
else
lab_message.Text = "修改失败!!!";
}
------解决方案--------------------
是报错还是更新不成功,你把语句打印处理看看。
sql语法上没有错误啊。
只要不是int等类型,即使更新为''也不会有问题。
如果是更新不成功,会不会是主键txt_serch没有值。 where id='" + txt_serch.Text + "'