更新语法错误? [英] update syntax error ?

查看:78
本文介绍了更新语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此..中可能出现的语法错误是什么.



q1 ="UPDATE客户端SET名称="& txtname.Text& ",add ="& txtadd.Text& ",contact ="& txtco.Text& ",email ="& txtemail.Text& ",bal =& txtbal.Text& 其中ID =& cid& ;"


此命令显示为语法错误... :(

请帮忙..

what could be possible syntax error in this ..



q1 = "UPDATE clients SET name=''" & txtname.Text & "'',add=''" & txtadd.Text & "'',contact=''" & txtco.Text & "'',email=''" & txtemail.Text & "'',bal=" & txtbal.Text & "where ID=" & cid & ";"


this command is showing as syntax error... :(

please help..

推荐答案

您想要列表吗?

不要连接字符串以构建SQL命令.它使您对意外或蓄意的SQL注入攻击敞开大门,这可能会破坏整个数据库.请改用参数化查询.它还经常会引起类似这样的问题.

您的文本框的内容是什么?由于您将其作为字符串的一部分传递给SQL,因此在尝试诊断问题时非常相关.
Would you like a list?

Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. It also frequently causes problems like this.

What is the content of your textboxes? Since you are handing it to SQL as part of a string, it is very relevant when tryingf to diagnose a problem.
q1 = "UPDATE clients SET name=@NAME,add=@ADD,contact=@CONT,email=@EMAIL,bal=@BAL WHERE ID=@ID"


然后将参数传递给您的SqlCommand对象:


Then hand the parameters to your SqlCommand object:

cmd.Parameters.AddWithVAlue("@NAME", txtname.Text)
cmd.Parameters.AddWithVAlue("@ADD", txtadd.Text)
cmd.Parameters.AddWithVAlue("@CONT", txtco.Text)
cmd.Parameters.AddWithVAlue("@EMAIL", txtemail.Text)
cmd.Parameters.AddWithVAlue("@BAL", txtbal.Text)
cmd.Parameters.AddWithVAlue("@ID", cid)


嗨酷aashi143,

您的错误在
Hi cool aashi143,

your error is near
bal= txtbal.Text 


附近 将其更改为


change it to

bal= cint(txtbal.Text)



原因是当您将值发送到数据库时,必须将具有数字值的字段转换为 Number/Integer .这里CInt会将txtbal文本框中的值转换为整数,就像在String中一样,因为文本框中的所有内容都被视为String.



谢谢



Reason is when you send values to database the field with numeric values must be converted to Number/ Integer. Here CInt converts the value in the txtbal Textbox to integer as it was in String as everything in textbox is considered as String.



Thanks,


这篇关于更新语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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