Jump to content
  • Advertisement
Sign in to follow this  
coolblue

[web] How do I pass a parameter to a LIKE query?

This topic is 3783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a query in acces which is similar to the following: Select name FROM tblNames WHERE name LIKE "*" & [@name] & "*"; This works fine from within access, it asks me for the parameter, I enter it and it gives be the result. The problem comes when I Pass the parameter from .net. It always returns null! How do I pass the parameter to the query from .net?

Share this post


Link to post
Share on other sites
Advertisement
You'll need to use the percent sign (%) in place of the asterisks.

EDIT: Oh, and [@name] is invalid:

string name = "Patrick";
...
"WHERE name LIKE '%" + name + "%'";

Share this post


Link to post
Share on other sites
Quote:
Original post by smr
You'll need to use the percent sign (%) in place of the asterisks.

EDIT: Oh, and [@name] is invalid:

string name = "Patrick";
...
"WHERE name LIKE '%" + name + "%'";



I did not think access recognises % sign for like operations and I usually use @parameter for the parameter names in access and they work fine. I am not writing this query string on the server side it is residing in a query within access like a stored procedure.

Share this post


Link to post
Share on other sites
Ok, I have found out what is needed, and why.

Aparently it is due to the fact that when calling the query as a stored procedure, the query should be written for the Jet engine and not access. So I needed to use percent sign and single quotes. as in the following.

WHERE name LIKE '%' & [@name] & '%';

A bit confusing as if I use the query from within access I need to use * and double quotes....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!