[Last Call] Learn how to a build a cloud-first strategyRegister Now


SQL LIKE Clause With CommandParamters in ASP.NET

Posted on 2006-05-25
Medium Priority
Last Modified: 2007-12-19
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?
Question by:developernetwork
  • 2
  • 2
LVL 28

Expert Comment

ID: 16762865
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.

Author Comment

ID: 16762917
No, there is no such method available.

Author Comment

ID: 16762925
And the '%' doesn't work even if I hardcode it using the SelectParameters collection.
LVL 28

Accepted Solution

strickdd earned 2000 total points
ID: 16763189
Try "%" instead of '%' in my code

Expert Comment

ID: 16763254
If you use objectdatasource in 2.0 then you do something like this.

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question