Click here to Skip to main content
15,921,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me friends...........


in window form i have 2 different-2 criteria to filter data for THERE i haveTWO cheakesdlistbox(1st for partyname and 2ND one for itemname) each contain number of items let if user select(by cheeking cheak box) 10 party name now he SELCT ithemname may he select all item or sum now as he press show button data should be fill in datagridview with the above selection ..CRITERIA.......now i want to pass these selected values in whare clause ..like..whrere partyanme="all value from partyname" and exchangetype="all selected exhange type"and itemname="selected itemname"....
please help me how to write selct query with multiple selected values....


IT IS ALSO possible ... USER NOT SELECT ANY ITEM BUT SELECT ALL PARTY

C#.sqlserver

thanks in advanced
Posted

See here's example of passing multiple values in a WHERE clause check it out..it surely useful as i have used in my project

SQL
CREATE PROCEDURE [dbo].[Get_Activity]
(

@i_Head_id varchar(10),
@i_Level_id varchar(10)
)as
SELECT     Unit_of_Material_Master.s_Unit_of_material, Activity_Master.s_Description, Activity_Master.i_Unit_of_material_id, Activity_Master.i_Head_id, 
                      Activity_Master.i_Level_id
FROM         Activity_Master LEFT OUTER JOIN
                      Unit_of_Material_Master ON Activity_Master.i_Unit_of_material_id = Unit_of_Material_Master.i_Unit_of_material_id
where  i_Head_id=@i_Head_id and i_Level_id=@i_Level_id 
 
Share this answer
 
v2
Separate the criteria with 'AND' or 'OR' after 'WHERE' clause.
 
Share this answer
 
you can code like
C#
string sql;
"select * from table where"+sql

if(item.checked==true)
{
sql=your condition;
}
else if(item1.cheked==true)
{
sql=your condition;
}
 
Share this answer
 
v3
Also if you have several values for the same field creating OR chains is sometimes troublesome. In these kind of cases you can use IN operator to simplify the query. For example if you have field No and you want to select rows having No 1 or 3 or 7 then you can write:
SQL
WHERE tableAlias.No IN (1,3,7)
Also in real life situation always remember to use SqlParameter[^] to define the values for a query.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900