Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
protected void Button1_Click(object sender, EventArgs e)
       {
           SqlConnection con = new SqlConnection("Data Source=xenorix8-PC;Initial Catalog=sachi;Persist Security Info=True;User ID=sa;Password=123");
           SqlCommand cmd = new SqlCommand("select * from tablename where convert(varchar(25),columnname,126) like '%" + TextBox1.Text + "%'", con);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);

           GridView1.DataSource = dt;
           GridView1.DataBind();
       }


What I have tried:

i'am using above code ,in that sql query is correct, but gridview was not displayed what i'am wrong? please tell me.
in that,
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
these two lines are correct or wrong?
Posted
Updated 24-May-16 3:24am
v5
Comments
CHill60 24-May-16 8:57am    
Never use concatenated strings to create SQL statements - especially if you include user input. Use parameterised queries instead. Apart from helping to protect you from SQL Injection attacks it very often removes issues like this.

When you debug what does cmd.CommandText contain? And what datatype is columnname?
F-ES Sitecore 24-May-16 9:00am    
Does the datatable have rows in it? Post the relevant mark-up. Also look to use parameterised queries rather than string concatenation to build SQL as your code is liable to sql injection attacks.
Nagarjuna99 24-May-16 9:00am    
sorry,i can mistaking in update time, acthually i'am using sql server.i check query in sql server output is coming. my problem is gridview
jgakenhe 24-May-16 9:09am    
When you debug it, you should be able to tell if there are rows of data in your datatable. If there are then the gridview is fine, you just can't see it. Check to see if the gridview has visibility set to false; if so, then you'll need to set it to true in your button click event.
Nagarjuna99 24-May-16 9:13am    
ya now i can add Visible = true;,but there is not come

1 solution

 
Share this answer
 
v2
Comments
Nagarjuna99 24-May-16 9:27am    
oho , thanks
Karthik_Mahalingam 24-May-16 9:32am    
:)

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