如何在VBScript中将ADODB参数化查询与adArray数据类型一起使用? [英] How to use ADODB parameterized query with adArray data type in VBScript?
问题描述
我无法在任何地方找到如何使用它的示例。我试图用参数化查询做一个简单的SELECT语句。我想使用adArray数据类型。这是一个示例
I have not been able to find an example of how to use this anywhere. I am trying to do a simple SELECT statement with a parameterized query. I want to use the adArray data type. Here is an example
sql = "SELECT * FROM table WHERE id IN ?"
set objCmd = Server.CreateObject("ADODB.Command")
set objParam = objCmd.Createparameter("@id", 0x2000, 1, length, arrMyArray)
objCmd.Parameters.Append objParam
这会引发错误的类型错误。我很好奇是否有人曾经尝试过这个工作或有任何例子。
This throws a wrong type error. I was curious if anyone has ever gotten this to work or has any examples. That'd be great.
谢谢您的帮助!
推荐答案
我不知道哪个数据库提供程序将支持数组。
I have no idea which database providers will support arrays.
我更喜欢做的是将数组作为单个长字符串传递,然后使用称为Split的UDF。 ()。结果是这样的:
What I prefer to do is pass the array as a single long string, then use a UDF called Split(). The result is something like this:
sql = "SELECT * FROM table WHERE id IN (Split(?))"
set objCmd = Server.CreateObject("ADODB.Command")
myBigString = ConvertArrayToCSV(arrMyArray) ' you have to write this, of course
set objParam = objCmd.Createparameter("@id", 200, 1, length, myBigString)
objCmd.Parameters.Append objParam
Here's a discussion of the Split() concept.
编辑
我已纠正上述问题(参数类型为200,而不是0x2000),现在我还看到ADO似乎支持以下语法:
I corrected the above (the parameter type is 200, not 0x2000), and I also now see that ADO appears to support this syntax:
0x2000 OR 129 ' array of strings
0x2000 OR 200 ' array of varchar
的数组,但我尚未对此进行测试。
But I haven't tested this.
这篇关于如何在VBScript中将ADODB参数化查询与adArray数据类型一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!