469,906 Members | 2,189 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,906 developers. It's quick & easy.

Multiple Select listbox and sql stored procedure -Help needed

Hi,
I've got listbox in my .aspx page where the users can make multiple
selection.
So, Users can select 7 items in listbox, I have to take value from
items and
pass it to stored procedure to extract a dataset back.

1.What should i do while passing the multiple selected values
2.Can i use 'in' clause in SQL procedure like
eg:Select a.xxx from a where a.yyy in @y
@y is the multiple selected values from listbox.
3.How to concatenate and send to SQL Procedure.
Please help me

Sep 4 '06 #1
1 3045
On 4 Sep 2006 00:01:52 -0700, "karups" <al***********@gmail.comwrote:
>Hi,
I've got listbox in my .aspx page where the users can make multiple
selection.
So, Users can select 7 items in listbox, I have to take value from
items and
pass it to stored procedure to extract a dataset back.

1.What should i do while passing the multiple selected values
2.Can i use 'in' clause in SQL procedure like
eg:Select a.xxx from a where a.yyy in @y
@y is the multiple selected values from listbox.
3.How to concatenate and send to SQL Procedure.
Please help me
This code will create a string you can use for the parameter, but I don't think
you can pass it into a stored procedure as a parameter. You may have to resort
to a command object with dynamically created SQL.

Command.Text = "SELECT YourTable.xxx from YourTable where YourTable.xxx in (" +
param + ")";

// simulation of what you are wanting to do.

StringBuilder sb = new StringBuilder("{0}");
bool first = true;
string vals = string.Empty;
for (int i = 1; i < 7; i++)
{
sb.Append(",{");
sb.Append(i.ToString());
sb.Append("}");
}

// produces "{0},{1},{2},{3},{4},{5},{6}"
// use vals as your parameter format string

vals = sb.ToString();

string param = string.Format(vals, 10, 20, 30, 40, 50, 60, 70);

// param = "10,20,30,40,50,60,70"

// yourcommand.Parameters.AddWithValue("@inParam", param);

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Sep 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Lauren Quantrell | last post: by
2 posts views Thread by Patrick Olurotimi Ige | last post: by
8 posts views Thread by Steve Schroeder | last post: by
16 posts views Thread by Randy Harris | last post: by
2 posts views Thread by =?Utf-8?B?VGVycnk=?= | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.