[英]Microsoft OLE DB Provider for SQL Server error '80040e14'
Stored procedure, and using ADO to connect, i'm having problems with the quotes however.. 存储过程,并使用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 & "'"
I thought i was doing this right.. But I guess not, because i'm getting this error: 我以为我做对了。。但是我想不是,因为我遇到了这个错误:
Microsoft OLE DB Provider for SQL Server error '80040e14'
SELECT ID from Table where Name='text''
Shouldn't it be 不是吗
Name = 'text'''
名称='文字'''
Why isn't SQL recognizing the double quotes using ADO? 为什么SQL无法使用ADO识别双引号?
The Select_SP Uses something like this: Select_SP使用如下所示的内容:
SET @sql = 'SELECT ID from Table where Name='''+@name+''''
Exec(@sql)
Do I have this SP written correctly? 我是否正确编写了此SP?
The short answer is, don't call procedures the way you're doing it. 简短的答案是,不要以您的方式调用过程。 Use a
Command
instead. 请改用
Command
。 This is from memory, since I don't have a Windows system in front of me at the moment, but it should work: 这是从内存中获取的,因为目前我还没有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
Now, all that said, I can't tell you why your procedure is giving that particular output since you're not showing us the code for it. 现在,所有这些,我不能告诉您为什么您的过程为什么要提供特定的输出,因为您没有向我们显示其代码。 But I'm fairly certain ADO isn't going to convert a pair of single quotes into a double quote - not sure why you'd expect it to.
但是我相当确定ADO不会将一对单引号转换为双引号-不知道为什么会这样。
Edit after seeing the OP's edit. 看到OP的编辑后进行编辑。 Don't execute SQL that way unless you absolutely have to.
除非绝对必要,否则不要以这种方式执行SQL。 You will only give yourself grief.
你只会给自己悲伤。 I don't know what database you're using and that procedure syntax doesn't look familiar, but in Oracle you could write something like:
我不知道您正在使用哪个数据库,并且该过程的语法看起来并不熟悉,但是在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.