Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

C#
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;
       GridView1.DataBind();



by using this now also i didn't get the result

thank u
Posted
Updated 31-Mar-11 2:42am
v4

All of the solutions are correct. But you may need to add %% on query param.
try here:
C#
string q1 = "select * from register where  areaofspecific like @area";
cmd.Parameters.AddWithValue("@the", "%"+textBox4.Text+"%");

Not Here:
C#
string q1 = "select * from register where  areaofspecific like '%@area%'";


Finally I'll say to do this:
type %myarea% inside your textbox4 and code:
MIDL
string q1 = "select * from register where  areaofspecific like @area";
cmd.Parameters.AddWithValue("@the",textBox4.Text);

Because user will decide, will he give % or not inside his query.
 
Share this answer
 
DataSet ds = new DataSet();
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;
GridView1.DataBind();
 
Share this answer
 
Its an example.
try this

C#
string value = TextBox1.text;
Cmd = new SqlCommand("DELETE FROM Table WHERE CountryMasterId = @ID", Con);
 Cmd.Parameters.AddWithValue("@ID", value );
 
Share this answer
 
v2

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