How to use ADODB parameterized query with adArray data type in VBScript?

南楼画角 提交于 2019-12-11 02:21:41

问题


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.

Thanks for the help in advance!


回答1:


I have no idea which database providers will support arrays.

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.

Edit

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.



来源:https://stackoverflow.com/questions/9315002/how-to-use-adodb-parameterized-query-with-adarray-data-type-in-vbscript

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