Sunday, August 2, 2009

Something wrong with my Search Page in ASP.Net?

C#





I made a search page that searches all the brand names in my table and this is my query:





adp = new SqlDataAdapter("select * from tblVitamins2 where Type like %"+TextBox1.Text+"%", conn);


adp.Fill(dt);





When I click the search button, this message appears:


Invalid Syntax near 'Multivitamins'





What do I do?





How do you make your search pages?





One more thing. How do I clear the DataTable so that it won't be filled with past searches?

Something wrong with my Search Page in ASP.Net?
I'm no ASP.NET wizard, but I'm guessing you typed in Multivitamins into your search textbox. I believe your problem is that:


"select * from tblVitamins2 where Type like %" + TextBox1.Text + "%"


should be:


"select * from tblVitamins2 where Type like '%" + TextBox1.Text + "%'"





That is, put a single quote (') before the first % and after the second %.


No comments:

Post a Comment