I have created a database and have presented the data in a gridview using Visual Studio C#. I am trying to write a query method that will search for an employee’s name and return all results that are similar to the name.
SELECT personID, name, address, phoneNumer, age FROM dbo.person WHERE name Like @name
Any advice/help on this would be hugely appreciated. I can’t seem to find a solution.
The LIKE clause uses wildcards to substitute letters. One of the most used wild cards is % which translates to ‘anything can go in here’, so when your LIKE clause looks like this:
It will retrieve all records that have a name that starts with Tina, while this one:
This will retrieve all records that have Tina anywhere. By default this is case insensitive I believe, unless you change your DB’s collation.
So make the value in your @name parameter include a wildcard somewhere, unless you want to look for an exact match.