?
Solved

passing an array as a parameter to a sqlDataAdapter

Posted on 2003-10-27
5
Medium Priority
?
902 Views
Last Modified: 2012-06-22
I have a dataadapter in a data class with a sql statement like this.
Select * from Customers where CustomerID = @ CustomerID

In my Code I am passing the parameter to the dataadapter like this.
OrdersData.sqlDaInvoiceByID.SelectCommand.Parameters["@CustomerID"].Value = paramValue;

I have an array with multiple customerIDs in it.  is there anyway to pass this array as the Value.  I tried just setting paramValue = myArray put it said input sting not in correct format.

Any ideas?
0
Comment
Question by:lyptus
[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
5 Comments
 
LVL 1

Expert Comment

by:jlach
ID: 9630146
I do not know how to do that, but i do know that you can create your sql at run time, and just execute the command... like

string ids = "0";
foreach(string str in Collection.Item) {
   ids += "," + str;
}
string sql = "select * from Customers where CustomerID in (" + ids + ")";

Then execute that sql..
0
 

Author Comment

by:lyptus
ID: 9630159
The command is in a class which I don't have access to.
0
 
LVL 1

Expert Comment

by:jlach
ID: 9630200
Then no, i dont think there is way to do this.. i dont use the whole adapter thing for paramaters and such.. do you have access to inherit anything from the class?
0
 
LVL 4

Expert Comment

by:aponcealbuerne
ID: 9635444
Hi

If the parameter is for example some string like 'a,b,c,d' and you want to use that values in the stored procedure then.
I think you have to choices.
a) To transform the parameter in the stored procedure by using substrings, or pathindex function in order to extract the elements of the array. In this way you could use some separators like the character '~' or any other separator character.

b) Other way to do this is by using directly the parameter, something like this.

Procedure x ...

@param1 varchar(100)

begin
 ... something ...

  eval('Select Field From Table Where Id in (''' + @param1 + ''' ) ')

.. something...

end

Hope helps.
0
 
LVL 2

Accepted Solution

by:
doryllis earned 1000 total points
ID: 9646306
Looking at the whole thing, if you do not have access to the sql command to change it from an equal sign to a LIKE or IN, then it won't help to do just the list of params into a string.  

If you can't change the query, one alternative is to call the sql query for each item in your array and gather those results together.
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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 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