?
Solved

Passing Multiple Paremeters from string to integer using IN clause

Posted on 2012-03-23
2
Medium Priority
?
429 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
ingriT earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

764 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