Click here to Skip to main content
15,920,110 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to pass cheakeedlistbox value in where clause in select query(sql2005)
Posted
Comments
[no name] 8-Dec-11 3:21am    
please help me frieds...........i have three chkeakedlistbox and i want to show data which filter from these three chkeakedlistbox

what is procedure and how to write select query ....C#,sqlserver

Hi,

Well a starting point would be, getting hold of the checked items:

CheckedListBox - Selected Item[^]

Secondly, StringBuilder is a great way of builing up the SQL string: StringBuilder Class and example[^]

Lastly, I would not pass the clear text string into the where clause, the application would become vulnerably to SQL injection, rather make use of named parameters.

Kind regards,
 
Share this answer
 
Comments
[no name] 8-Dec-11 3:30am    
thanks .....sorry but can u describe what actually i have to do

my query............string sqlqry = "SELECT ITEMCODE, BROKTYPE,BROKRATE,TRANRATE,TranType,uptostdt,MARTYPE,MARRATE,PARTYTYPE FROM PITBROK where ITEMCODE='" + str3 + "' ";

SqlDataAdapter da = new SqlDataAdapter(sqlqry, con);
DataSet ds1 = new DataSet();
da.Fill(ds1, "PITBROK");

//if (ds1.Tables[0].Rows.Count > 0)
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
//for (int j = 0; j < ds1.Tables[0].Columns.Count; j++)
//{
dataGridView1.ColumnCount = 9;
dataGridView1.Rows.Add();

dataGridView1[0, i].Value = ds1.Tables[0].Rows[i][0].ToString();
//dataGridView1[1, i].Value = ds1.Tables[0].Rows[i][1].ToString();
string b = ds1.Tables[0].Rows[i][1].ToString();

if (b == "O")
{

dataGridView1[1, i].Value = "Opening Sauda";
dataGridView1[1, i].Style.BackColor = Color.LightBlue;
}
else if (b == "P")
{

dataGridView1[1, i].Value = "Persentage Wise";
dataGridView1[1, i].Style.BackColor = Color.SteelBlue;
}
else if (b == "T")
{

dataGridView1[1, i].Value = "Transaction";
dataGridView1[1, i].Style.BackColor = Color.Tomato;
}
dataGridView1[2, i].Value = ds1.Tables[0].Rows[i][2].ToString();
dataGridView1[3, i].Value = ds1.Tables[0].Rows[i][3].ToString();
string l = ds1.Tables[0].Rows[i][4].ToString();


if (l == "O")
{

dataGridView1[4, i].Value = "Opening Sauda";
dataGridView1[4, i].Style.BackColor = Color.LightBlue;
}
else if (l == "P")
{

dataGridView1[4, i].Value = "Persentage Wise";
dataGridView1[4, i].Style.BackColor = Color.SteelBlue;
}
else if (l == "T")
{

dataGridView1[4, i].Value = "Transation";
}


dataGridView1[5, i].Value = ds1.Tables[0].Rows[i][5].ToString();
string m = ds1.Tables[0].Rows[i][6].ToString();
if (m == "Q")
{

dataGridView1[6, i].Value = "Qty Wise(perunit)";
}
else if (m == "V")
{

dataGridView1[6, i].Value = "Value Wise(in%)";
}
else if (m == "I")
{

dataGridView1[6, i].Value = "Import Rates";
}
else if (m == "C")
{
dataGridView1[6, i].Value = "Client Wise Margine";
}

dataGridView1[7, i].Value = ds1.Tables[0].Rows[i][7].ToString();
dataGridView1[8, i].Value = ds1.Tables[0].Rows[i][8].ToString();

}
// }
You need to pass the value of the checkedlistbox to the query as a boolean.

FOr e.g. if your checkbox is checked, your where clause would be something like where myColumn = true.
 
Share this answer
 
Comments
[no name] 8-Dec-11 7:36am    
but i have no cheakbox its cheakedlistbox which have more than one value may 10..or 15..or 15 select at a time

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