Passing Multiple Paremeters from string to integer using IN clause

TRA_DEV
TRA_DEV used Ask the Experts™
on
I have a query "SELECT NAME FROM TABLE WHERE PKEY IN(@PKEY)".  Seems simple enough, but @PKEY is my problem.  I always get the "unable to convert type varchar to int" message.  I've tried numerous different ways from arrays to arraylist.  What I'm currently trying to pass resembles:  '1,5,9'

I should mention that the data source is for a Telerik report.  Some things I've tried:

Me.dataSource.Parameters("@CHECKS").Value ='" & key & "')  (where key would be:  '1,5,9'

Any help would be greatly appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can't pass multiple parameter values in one parameter.

You could do it without the parameter;
"SELECT NAME FROM TABLE WHERE PKEY IN(" & key & ")"

Or you should rewrite the code/query to do multiple queries, one for each key.

int[] keys = key.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (int index = 0; index < keys.Length; index++)
{
"SELECT NAME FROM TABLE WHERE PKEY = @CHECKS"
Me.dataSource.Parameters("@CHECKS").Value = keys[index]
}

Commented:
Look at raghav_khunger's answer to this post.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial