i have a text box with a search button.on the click of button i want to fetched all the values start with any alphabet say 'm' and bind to grid view.i hv used a query
sqlcommand cmd=new sqlcomand("select * from table where pname='"+textbox1.text+"'%",con);
rajeevinime
Member
406 Points
229 Posts
use of like % in sqlcommand
Jul 15, 2010 04:09 AM|LINK
i have a text box with a search button.on the click of button i want to fetched all the values start with any alphabet say 'm' and bind to grid view.i hv used a query
sqlcommand cmd=new sqlcomand("select * from table where pname='"+textbox1.text+"'%",con);
but it shows that invalid term % how to do this
pls help me
regards
rajeev
Rajeev Kumar
Mark As Answer If It Helps You
Naom
All-Star
36004 Points
7901 Posts
Re: use of like % in sqlcommand
Jul 15, 2010 04:47 AM|LINK
Try
SqlCommand cmd=new SqlComand("select * from table where pname LIKE @Name + '%'",con); cmd.Parameters.AddWithValue("@Name",textbox1.text)(Donald Knuth)
Visit my blog
Microsoft Community Contributor 2011-12
1Madhu
Member
317 Points
119 Posts
Re: use of like % in sqlcommand
Jul 15, 2010 04:53 AM|LINK
Hi Rajeevinime,
Bug in your query is
You have to write like this:
sqlcommand cmd=new sqlcomand("select * from table where pname like '" + textbox1.text + "'%",con);
Hope this helps!
Regards,
Madhu,India