[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

Passing Multiple Paremeters from string to integer using IN clause

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.
0
TRA_DEV
Asked:
TRA_DEV
1 Solution
 
ingriTCommented:
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]
}
0
 
RickCommented:
Look at raghav_khunger's answer to this post.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now