Listbox items to Stored Procedure

R

r3net

I need to pass a parameter @item to a stored procedure
and get back a selection based on value(s) contained in
@item.

@item is a collection of selected items in a listbox as
follows...
ArrayList alItems = new ArrayList();
foreach(ListItem li in listbboxItems.Items)
{
if(li.Selected == true)
alItems.Add (li.Value);
}

Questions...
1. How do I define the SqlDbType for an array and assign
aiItems to it?
ie...Item_Command.Parameters.Add("@item",
SqlDbType.VarChar, 250).Value = aiItems.ToString();
note: I am using "VarChar, 250" only to clarify my
question.

2. How do I define @items in SQL so that the following
would result
SELECT * FROM tbl WHERE tbl.items IN @item
***or/same as***
SELECT * FROM tbl WHERE tbl.items IN ('AR', 'BC', 'mBR')

Thanks,
Koy
 
N

Nicholas Paldino [.NET/C# MVP]

Koy,

You can't do this (pass sets/arrays as parameters). You will have to
find some other way of doing this (perhaps by storing the values in a table
somewhere and then having your query join on that table).

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top