Solved

Passing Multiple Paremeters from string to integer using IN clause

Posted on 2012-03-23
2
416 Views
Last Modified: 2012-03-23
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
Comment
Question by:TRA_DEV
2 Comments
 
LVL 6

Accepted Solution

by:
ingriT earned 500 total points
ID: 37757434
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
 
LVL 13

Expert Comment

by:Rick
ID: 37757709
Look at raghav_khunger's answer to this post.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A short film showing how OnPage and Connectwise integration works.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now