无效的语法 [英] Invalid syntax
本文介绍了无效的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
晚上好
在vb.net(SQL数据库服务器)中执行我的应用程序期间,出现语法错误..
代码:Dim cd作为新的SqlClient.SqlCommand("select * from Fournisseur where Code =" + ComboBox2.Text,cnx)
错误("="附近的语法无效)
请,您能帮我解决这个问题吗?
Good evening
During the execution of my application in vb.net (SQL database server) is a syntax error appears ..
code: Dim cd As New SqlClient.SqlCommand("select * from Fournisseur where Code=" + ComboBox2.Text, cnx)
Error (Invalid syntax near ''='')
Please, Can you help me solve this problem?
推荐答案
使用SqlCommand而不是字符串连接.不确定这是否是您的问题,但是还是有问题.
Use SqlCommand rather than string concatenation. Not sure that is your problem, but it is a problem anyway.
您的代码"字段是一个字符串,并且来自ComboBox的文字值需要用双引号引起来,或者代码"字段是字符串和来自ComboBox的值需要解析(可能还有一对定界符,具体取决于类型).无论哪种方式都是错误的.
并且,正如aspdotnetdev已经说过的,建议使用参数化的SQL命令(当ComboBox中的值不打算用作字符串时,仍然需要解析).
:)
Either your Code field is a string and the literal value coming from the ComboBox needs double quotes, or the Code field isn''t a string and the value coming from the ComboBox needs parsing (and possibly a pair of delimiters, that depends on type). Either way it is wrong.
And, as aspdotnetdev already said, using a parameterized SQL command is recommended (it would still require parsing when the value from the ComboBox isn''t intended as a string).
:)
Hi,
Dim cd As New SqlClient.SqlCommand("select * from Fournisseur where Code=" + ComboBox2.Text, cnx)
替换为``&''而不是``+''
replace with ''&'' instead of ''+''
Dim cd As New SqlClient.SqlCommand("select * from Fournisseur where Code=" & ComboBox2.Text, cnx)
这篇关于无效的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文