Multiple Select listbox and sql stored procedure -Help needed

K

karups

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
 
O

Otis Mukinfus

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
 

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