【发布时间】:2015-05-08 15:02:52
【问题描述】:
我想将文本框的值更新到我的 SQL Server 数据库中。
代码没有显示任何语法错误,并且很容易重定向到我正在重定向的页面,但数据库仍然没有更新其中的新数据。
conn.Open();
string str_id = Session["userid"].ToString();
int id = Convert.ToInt32(str_id);
id = Int32.Parse(str_id);
string updatequery = "Update empdata set fname='" + updatename.Text + "',education='" + updateeducation.Text + "',position='" + updateposition.Text + "',email='" + updateemail.Text + "',address='" + updateaddress.Text + "',contact='" + updatecontact.Text + "',account='" + updateaccount.Text + "',postal='" + updatepostal.Text + "',password = '" + updatepwd.Text + "' Where id = '" +id.ToString()+ "'";
SqlCommand updateinfo = new SqlCommand(updatequery, conn);
updateinfo.ExecuteNonQuery();
updateinfo.Dispose();
updationmessage.Text="<p style='color:green;'>Information updated successfully</p>";
【问题讨论】:
-
xkcd.com/327这里是sql注入漏洞!
-
如果在设置 updatequery 后的行设置断点,则可以得到正在尝试的实际查询。此外,您的代码容易受到 sql 注入的影响。
-
文本框的初始值是否从数据库中加载?可能是回发问题
-
你能显示实例化 conn 的代码吗?
-
页面中是否启用了视图状态?
标签: c# sql asp.net sql-server database