use of like % in sqlcommand http://forums.asp.net/t/1579089.aspx/1?use+of+like+in+sqlcommand+Thu, 15 Jul 2010 04:53:42 -040015790893973601http://forums.asp.net/p/1579089/3973601.aspx/1?use+of+like+in+sqlcommand+use of like % in sqlcommand <p>i have a text&nbsp;box with a search&nbsp;button.on the click of button i&nbsp;want to&nbsp;fetched all the values start with any alphabet say 'm' and bind to grid view.i hv used a query </p> <p>sqlcommand cmd=new sqlcomand(&quot;select * from table&nbsp;where&nbsp;pname='&quot;&#43;textbox1.text&#43;&quot;'%&quot;,con);</p> <p>but it shows that invalid term % how to do this</p> <p>pls help me</p> <p>regards</p> <p>rajeev&nbsp;</p> 2010-07-15T04:09:36-04:003973657http://forums.asp.net/p/1579089/3973657.aspx/1?Re+use+of+like+in+sqlcommandRe: use of like % in sqlcommand <p>Try</p> <p><br> </p> <pre class="prettyprint">SqlCommand cmd=new SqlComand(&quot;select * from table where pname LIKE @Name &#43; '%'&quot;,con); cmd.Parameters.AddWithValue(&quot;@Name&quot;,textbox1.text)</pre> <p><br> <br> </p> <p><br> </p> 2010-07-15T04:47:24-04:003973673http://forums.asp.net/p/1579089/3973673.aspx/1?Re+use+of+like+in+sqlcommandRe: use of like % in sqlcommand <p>Hi Rajeevinime,</p> <p>Bug in your query is</p> <p><pre class="prettyprint">select * from table where pname like 'a%'</pre></p> <p>You have to write like this:</p> <p>sqlcommand cmd=new sqlcomand(&quot;select * from table&nbsp;where&nbsp;<b>pname like '&quot; &#43; textbox1.text &#43; &quot;'%&quot;</b>,con);</p> <p>Hope this helps!<br> </p> 2010-07-15T04:53:42-04:00