2
Answers

I have some problem in sqlcommand where condition to implement the c# coding

rasul moh

rasul moh

12y
2.3k
1
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ccc"].ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("select [Town Name] from town where '" + DropDownList1.SelectedItem.Text + "' <= '" + TextBox1.Text + "'", con); //ListBox1.Text = cmd.ExecuteScalar().ToString(); TextBox4.Text = cmd.ExecuteScalar().ToString(); con.Close(); In This coding after Where condition not use to textbox,label,dropdownlist,etc how can I use textbox,label,dropdownlist,etc send me answer quickly to rasulmoh@pits.co.in
Answers (2)
-1
Pradip Pandey
NA 6.9k 1.1m 12y
You have not written column name i.e filed name of the town table. change your code
SqlConnection(....
where <columnname1>='" + DropDownList1.SelectedValue + "' and <columnname2>='" + TextBox1.Text + "',con);

if columnname1 is integer type of filed then use DropDownList1.SelectedValue.
if columnname1 is varchar type of filed then use DropDownList1.SelectedItem.Text.



Hope it will help.

-2
sarfaraj md
NA 161 34.6k 12y
where id= '" + DropDownList1.SelectedItem.Text + "' and col= '" + TextBox1.Text + "'", con);