[英]Microsoft OLE DB Provider for SQL Server error '80040e14' Invalid column name . SQL query
[英]Microsoft OLE DB Provider for SQL Server error '80040e14'
存儲過程,並使用ADO進行連接,但是引號有問題。
x = "text'"
If instr(x,"'") then x=replace(x,"'","''")
'x = "text''" at this point
Set Rs = Server.Createobject("adodb.recordset")
Rs.Open "Select_SP @name='" & x & "'"
我以為我做對了。。但是我想不是,因為我遇到了這個錯誤:
Microsoft OLE DB Provider for SQL Server error '80040e14'
SELECT ID from Table where Name='text''
不是嗎
名稱='文字'''
為什么SQL無法使用ADO識別雙引號?
Select_SP使用如下所示的內容:
SET @sql = 'SELECT ID from Table where Name='''+@name+''''
Exec(@sql)
我是否正確編寫了此SP?
簡短的答案是,不要以您的方式調用過程。 請改用Command
。 這是從內存中獲取的,因為目前我還沒有Windows系統,但是它應該可以工作:
Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
Set Cmd.ActiveConnection = myConnectionVariableHere
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "Select_SP"
'Note: if the above two lines don't work, replace them with the following
'cmd.CommandType = adCmdText
'cmd.CommandText = "Select_CP @name=?"
cmd.Parameters.Append cmd.CreateParameter("name", adVarChar, adParamInput, len(x), x)
Rs.Open cmd
現在,所有這些,我不能告訴您為什么您的過程為什么要提供特定的輸出,因為您沒有向我們顯示其代碼。 但是我相當確定ADO不會將一對單引號轉換為雙引號-不知道為什么會這樣。
看到OP的編輯后進行編輯。 除非絕對必要,否則不要以這種方式執行SQL。 你只會給自己悲傷。 我不知道您正在使用哪個數據庫,並且該過程的語法看起來並不熟悉,但是在Oracle中,您可以編寫如下內容:
PROCEDURE sql_test(MyName IN VARCHAR2, MyCursor OUT SYS_REFCURSOR) IS
BEGIN
OPEN MyCursor FOR SELECT id FROM some_table WHERE name = MyName;
END;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.