By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Multiple Select listbox and sql stored procedure -Help needed

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.