Re: Multiple Select listbox and sql stored procedure -Help needed



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
.



Relevant Pages

  • Re: Parameters
    ... It looks like your performing a query against a stored procedure. ... > Obtaining Data Based Upon Multiple Selections From a ListBox... ... > In the listbox multiple selection i Tryed put: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Multiple Select listbox and sql stored procedure -Help needed
    ... I've got listbox in my .aspx page where the users can make multiple ... selection. ... 3.How to concatenate and send to SQL Procedure. ...
    (microsoft.public.dotnet.languages.csharp)
  • Multiple Select listbox and sql stored procedure -Help needed
    ... I've got listbox in my .aspx page where the users can make multiple ... selection. ... 3.How to concatenate and send to SQL Procedure. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: getting single selected value from listbox
    ... The combo is bound to a stored procedure but I only wish to obtain the value ... "Jeff Boyce" wrote: ... A listbox with, say, 4 fields displayed can have 17 fields, with a width ... I am not allowing multiple value selection so should ...
    (microsoft.public.access.forms)
  • databounded listbox with datagrid results complete description
    ... i have a databound listbox id "listboxcity" that has a multilple ... SqlDataReader citydr; ... till now it is working for single value selection and its succsseful ... Now how to make changes in it for multiple ...
    (microsoft.public.dotnet.framework.aspnet)