| hi, string q1 = "select * from register where areaofspecific like ' %+ TextBox1.Text + % ' and experience= '" + DropDownList1.SelectedItem.Value.ToString() + "'"; i wrote the query like this but when i execute the query in sql window the correct result will be displayed i gave the textbox value as .net,sqlin sql table there is c,c++,java,.net,sql but nothing will be displayed what can i do |
Loading

Suthish NairRank #92 · 22.8K reputationPosted Mar 31, 2011, 3:18 AM EDT
karthi vimala38 reputationPosted Mar 31, 2011, 5:08 AM EDT
when i used parameterized queries at that time also i didn't get the result
string=q1 = "select * from register where areaofspecific like '%@area%'";
using (SqlCommand cmd = new SqlCommand(q1, conn))
{
cmd.Parameters.AddWithValue("@area", TextBox4.Text);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
}
GridView1.DataSource = ds;
Aaron Colen30 reputationPosted Mar 31, 2011, 5:17 AM EDT
Use '%' + @Parameter + '%' instead of '%@Parameter%'.
Writing '%@Parameter%' the parameter is wrapped in quotes and is interpreted by SQL literally.
Suthish NairRank #92 · 22.8K reputationPosted Mar 31, 2011, 6:20 AM EDT
String q1 = "select * from register where areaofspecific like @area and experience = @exp";