开发者

Getting error in a like condition (Filter)

Using VB.Net and Sql Server

Query

Select cCustomerCode,cCustomerName from cms_Customer where cCustomerName like '%['" & frmCustomers.txtName.Text & "']%'

Th开发者_如何转开发e above query is showing error as "Incorret syntax near a"

What is problem with above query, whethere like condition is used properly or not.

Need Query or Code Help


Try,

str="Select cCustomerCode,cCustomerName FROM cms_Customer
     where cCustomerName like '%" & frmCustomers.txtName.Text & "%'"

OR

str="Select cCustomerCode,cCustomerName FROM cms_Customer
         where cCustomerName like @custName"
.....
cmd.Parameters.AddWithValue("@custName","%" & txtName.Text & "%")


[ is a special character in SQL server, you need to escape it

\[

See here http://web.archive.org/web/20150519072547/http://sqlserver2000.databases.aspfaq.com:80/how-do-i-search-for-special-characters-e-g-in-sql-server.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜