无法执行更新和删除等查询 [英] Can't perform queries like update and delete

查看:116
本文介绍了无法执行更新和删除等查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更新和删除vb.net中的记录?

How do I update and delete a record in vb.net?

cmd = New OleDbCommand("update empl set name =" & "'" & TextBox2.Text & "'" & "," & "city = " & "'" & TextBox3.Text & "'" & "," & "cont_no = " & TextBox4.Text & "," & "salary =" & TextBox5.Text & "where no=" & TextBox1.Text & , cn)



使用此查询,我无法更新记录,也无法删除



using this query I cant update my record and also delete

推荐答案

确保您的no参数存在一条记录.
在您的代码中的TextBox1.Text行上放置一个调试点,看看其中有什么值.
Make sure you have a record that exists for your no parameter.
Put a debug point in your code on the TextBox1.Text line and see what values come in there.


我认为no和cont_no是表empl中的字段,并且是数字类型,而不是字符类型.如果它们是字符类型,则需要在where子句中用引号括起从TextBox1和TextBox2获取的文字.

旁注:请不要像这样拼凑您的SQL语句.使用SQL参数,因为它们可以使您免受SQL注入攻击的侵害,并提高SQL语句的可读性.

最好的问候,
曼弗雷德(Manfred)
I take it that no and cont_no are fields in table empl and are number types and not a character types. If they were of character type you would need to put quotes around the literals you take from TextBox1 and TextBox2 inside your where clause.

A side note: Please don''t piece together your SQL statement like that. Use SQL parameters as they will keep you safe from SQL injection attacks and give you better readability of your SQL statements.

Best Regards,
Manfred


这篇关于无法执行更新和删除等查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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