?
Solved

passing an array as a parameter to a sqlDataAdapter

Posted on 2003-10-27
5
Medium Priority
?
928 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
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

749 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