Re: Multiple Select listbox and sql stored procedure -Help needed
- From: Otis Mukinfus <phony@xxxxxxxxxxxxxxxx>
- Date: Mon, 04 Sep 2006 10:44:32 -0500
On 4 Sep 2006 00:01:52 -0700, "karups" <al.karuppaiah@xxxxxxxxx> wrote:
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
.
- References:
- Prev by Date: fixing up a string to make it a valid XML attribute name ...
- Next by Date: Re: registry problem
- Previous by thread: Multiple Select listbox and sql stored procedure -Help needed
- Next by thread: validation of an xml file against multiple defined schema
- Index(es):
Relevant Pages
|