Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi All,
 
I have one from with list box, my listbox shows client names and selection mode is multiple. am select the 3 or more items then click on search button.
 
single selection is working fine and display data correct. but 1 or more selection in my list box query is not working. how to write the query.?
 
in database client-name field is there.
 
how to search the data single column with multiple client names.i.e am given to client_name='san,jhone,dev' then display the related data on these client-names.
 
how to display please help me
Posted 29-Jan-13 1:24am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Alternatively, bind your listbox with setting DataValueField property as client_id and DataTextField as client_name.
 
You can send the Client_ID's [assuming that column is present in your database] as comma separated values and in select query you can write
select client_id in (1,2,3) -- where 1,2,3 are selected client ids.
  Permalink  
v2
Comments
Santhosh23 at 29-Jan-13 7:39am
   
thank for the your replay. actually i don't have client_id field. and am passing the client-names. depend on user selection. so how to split the values by using , in database. actually we don't no for how many selections in client names
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

First prepare string variable which contains all selected values in listbox separated by comma(,) with following code
 
string selecteditems = "";
for (int i = 0; i < listBox1.Items.Count; i++)
{
 if (listBox1.GetSelected(i))
 {
   selecteditems += "'"+listBox1.GetItemText(listBox1.Items[i])+"',";
 }
}
selecteditems = selecteditems.Remove(selecteditems.Length - 1);
 

Now write ur select query as
 
" Select * from clienttable where client_name in ("+ selecteditems +")"
this will surely help u..
 
hav a great time.
If it helps u dnt forget to click on accept ans and vote for it.
enjoy Smile | :)
  Permalink  
Comments
Santhosh23 at 29-Jan-13 8:08am
   
thank for your replay, just now am tring your query am selection two names in listbox. SELECT RECORDID,AVAILABILITY,EMPLOYEMENTSTATUS,CLIENTNAME,DOB,SKILLS,EMAILID,VISA,CREATEDDATE,LOCATION,CITY+', '+C_STATE as LOCATION FROM dbo.RECORDDETAILS where CLIENTNAME='newclient,gdgf' but no records found my query like this
kshitij_CodeMaster at 29-Jan-13 8:11am
   
rewrite query as SELECT RECORDID,AVAILABILITY,EMPLOYEMENTSTATUS,CLIENTNAME,DOB,SKILLS,EMAILID,VISA,CREATEDDATE,LOCATION,CITY+', '+C_STATE as LOCATION FROM dbo.RECORDDETAILS where CLIENTNAME in ('newclient','gdgf')
Santhosh23 at 29-Jan-13 10:19am
   
your query working sql statement. same query how to write in stored procedure am execute procedure SELECT RECORDID,AVAILABILITY,EMPLOYEMENTSTATUS,CLIENTNAME,DOB,SKILLS,EMAILID,VISA,CREATEDDATE,LOCATION,CITY+', '+C_STATE as LOCATION FROM dbo.RECORDDETAILS where CLIENTNAME in (@CLIENTNAME) but exec SP_GET_RECORDDETAILS1 'Client Test','IBM','newclient' shows the error too many parameters. exec SP_GET_RECORDDETAILS1 'Client Test,IBM,newclient' its show no records how to write same query in stored procedure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 750
1 OriginalGriff 543
2 Abhinav S 318
3 thatraja 245
4 Tadit Dash 140
0 Sergey Alexandrovich Kryukov 8,322
1 OriginalGriff 4,790
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid