Link to home
Start Free TrialLog in
Avatar of developernetwork
developernetwork

asked on

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?
Avatar of strickdd
strickdd
Flag of United States of America image

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.
Avatar of developernetwork
developernetwork

ASKER

No, there is no such method available.
And the '%' doesn't work even if I hardcode it using the SelectParameters collection.
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you use objectdatasource in 2.0 then you do something like this.

<asp:ControlParameter DefaultValue="%" Name="firstname" ControlID="Dropdownlist1" Type="String" />