[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

passing an array as a parameter to a sqlDataAdapter

Posted on 2003-10-27
5
Medium Priority
?
912 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

656 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