SQL LIKE Clause With CommandParamters in ASP.NET

SelectCommand="SELECT id, firstname, lastname, code, phone FROM dbo.Customers WHERE (firstname LIKE @firstname '%') OR (lastname LIKE @lastname)"

I need to be able to look up Firstnames and lastnames using the Like% clause ( text/wildcard ). How can I implement this wit the command paramters in ASP.NET?
developernetworkAsked:
Who is Participating?
 
strickddCommented:
Try "%" instead of '%' in my code
0
 
strickddCommented:
SelectCommand="SELECT id, firstname, lastname, code, phone FROM dbo.Customers WHERE (firstname LIKE @firstname) OR (lastname LIKE @lastname)"

SelectCommand.Parameters.Add("@firstname", FirstName.Text +  '%');
SelectCommand.Parameters.Add("@lastname", LastName.Text + '%');



I think that might work.
0
 
developernetworkAuthor Commented:
No, there is no such method available.
0
 
developernetworkAuthor Commented:
And the '%' doesn't work even if I hardcode it using the SelectParameters collection.
0
 
skiltzCommented:
If you use objectdatasource in 2.0 then you do something like this.

<asp:ControlParameter DefaultValue="%" Name="firstname" ControlID="Dropdownlist1" Type="String" />
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.