i am trying to incorporate a basic search function on my webpage and display the results using a gridview. the thing, the codework on page_load but doesn't when I use a textbox + searchbutton.
heres the code:
SqlConnection conRead = new SqlConnection (@"Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|\projectDB.mdf;Integrated Security=True;User Instance=True"); SqlCommand cmdSel = new SqlCommand("SELECT * FROM Message WHERE Message LIKE '" + txtSearch.Text + "'", conRead);
conRead.Open();
SqlDataReader reader = cmdSel.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind();
|
like what i've said, it works if i put it on page_load (using select * from message) but doesn't on button1_click (using the sql statement above) where the condition parameter is based on the textbox input.
any help?