Code:
The OFFICE_ID values are int. How can I create a parameter of multiple int values?
I'm guessing you have an array of values.
I'd strongly recommend scanning it to be sure they're actually all integers. This code isn't VBScript but regular
VB as I'm not an ASP guy. If you're using ASP.NET (it does help to mention what language you're using) just make sure you type your arrays.
Code:
Dim a(1 To 3)
a(1) = 5
a(2) = 89
a(3) = "error"
For Each i In a
x = CInt(i) ' You don't have to do anything with x
Next
If UBound(a) - LBound(a) < 1 Then
inexpr = "1 = 1" ' Handle empty arrays correctly
Else
inexpr = "IN (" + Join(a, ", ") + ")"
End If
That code will fail when it tries to CInt the string. I'd recommend always checking this stuff before sending it to the DBMS. If the check is taking up too much time, you'll see that when you profile and you can easily remove it, but this is no different than the checks CreateParameter has to do.
To use it, you insert the value of inexpr in your SQL. It is, theoretically, possible to use parameters, but that's just another means of validating your inputs.