通过更新查询更新数据库中的数据 [英] updating data in database through update query

查看:145
本文介绍了通过更新查询更新数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的更新查询.

我没有收到任何错误,但是值没有更新到数据库中.


This is my update query.

I am not getting any errors but the values are not being updated into the database.


cmd.CommandText = "update registration set name =''" + txtname1.Text + "'',email_id=''" + txtemail1.Text + "'',degree=''" + txtdegree1.Text + "'',address=''" + txtaddress1.Text + "'' where employee_id=''" + txtemployeeid1.Text + "''";

推荐答案

尝试如下调试(假设您使用的是Visual Studio):

1.在下一行设置一个断点,然后在调试模式下运行程序.

Try to debug it as follows (Assuming you are using Visual Studio):

1. Set a breakpoint at the following line and run your program in debug mode.

cmd.CommandText = ...



2.当断点到达此行时,查看cmd.CommandText的值(使用监视或即时窗口)并复制该值.

3.在SQL Server Management Studio(或数据库服务器的查询窗口)中运行SQL.

4.看看会发生什么.如果运行不正常,请尝试分析SQL并查找问题.确保SQL正确.

5.现在,找到正确的SQL与从断点从cmd.CommandText属性复制的SQL之间的差异.修复生成错误SQL部分的代码.

希望您的问题得到解决

最好的祝愿



2. When the breakpoint hits this line, view the value of cmd.CommandText (Using watch or Immediate window) and copy the value.

3. Run the SQL in the SQL Server Management Studio (Or, the query window of your database server).

4. See what happens. If it does not run correctly, try to analyze the SQL and find problem. Make sure the SQL is correct.

5. Now, find the difference between the correct SQL and the SQL that you copied from the cmd.CommandText property from the breakpoint. Fix the code that is generating the wrong part of the SQL.

Hopefully, your problem will be solved

Best wishes


如果字段类型为数字,请不要使用引号:

"... where employee_id =" + txtEmployeeid1.Text +"
if type of field is number,don''t use quotation sign :

"... where employee_id=" + txtEmployeeid1.Text + ""


除了其他注释之外,您是否还绑定到prerender事件中的数据,如果您是b/c,这是在您的页面加载中完成的,您需要在更新之前进行绑定,这将使数据第一次停止显示在屏幕上.其次,假设您已解决此问题,我希望该应用程序永远不会在现实世界中使用,因为由于您的代码缺乏安全性,任何想要删除您的数据库的恶意用户都可以这样做.
In addition to the other comments, are you binding to your data in the prerender event, b/c if you''re doing it in your page load, you bind before you update, which would stop the data appearing on screen, first time. Secondly, assuming you resolved this, I hope this application will never be used in the real world, because any malicious user that would want to delete your database, could, due to a lack of security in your code.


这篇关于通过更新查询更新数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆