Microsoft OLE DB Provider for SQL Server error '80040e14' Incorrect syntax near '='

匿名 (未验证) 提交于 2019-12-03 00:50:01

问题:

I get this error when i try to retrieve the data from database using the following piece of code.

Can someone help?

set rs = Server.CreateObject("ADODB.recordset") sql = " SELECT * from COMPANY WHERE COMPANY_ID = " & Request.Form("CompanyId") rs.Open sql, cnn 

回答1:

First of all, this is bad practice to do ad-hoc queries without using parameters. SQL Injection attack info: http://en.wikipedia.org/wiki/SQL_injection

To answer the question, though, you need to have single quotes around your varchar or char value that you are searching for.

set rs = Server.CreateObject("ADODB.recordset") sql = " SELECT * from COMPANY WHERE COMPANY_ID = '" & Request.Form("CompanyId") & "'" rs.Open sql, cnn 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!