Click here to Skip to main content
15,883,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing ms access query using 'like' operator
"Select TNAME,TADDRESS from VILLAGEMST where TADDRESS like '*" & VILNAME & "*'"

When I run this query in ms access query wizard,it returns value from table.But when I run the application in vb.net and try to retrieve query value in dataset or recordset,it shows no value.Does any1 know whats the problem?
Posted

That is because "*" is not a wildcard in LIKE clauses. Try "%" instead:
VB
"Select TNAME,TADDRESS from VILLAGEMST where TADDRESS like '%" & VILNAME & "%'"
 
Share this answer
 
v2
Comments
Rachna0309 19-Nov-12 3:45am    
But in MS ACCESS * is used as a wildcard in LIKE clause
OriginalGriff 19-Nov-12 3:53am    
:blush:
Sorry - I didn't notice the Access bit and assumed SQL. You are right, "*" is an ACCESS wildcard.
So...what does the debugger say is the content of VILNAME?
Rachna0309 19-Nov-12 3:56am    
VILNAME is the value I get from another sql query which I pass as parameter to the above query.
OriginalGriff 19-Nov-12 4:00am    
Yes - but what string does it contain? You need to know because it is the relevant info that is being used for the query - if the previous request is returning empty or wrong data then the problem will show up here. The first thing to do is find out exactly what you are presenting Access with! :laugh:
Rachna0309 19-Nov-12 4:03am    
VILNAME contains village name.It returns Correct data.The only problem is when using like operator,records are not fetched in recordset,but runs well in query.
lol did you try the % instead? Had this problem too.
 
Share this answer
 
Comments
Maciej Los 29-Dec-14 11:19am    
Wrong!
I'd suggest to remove this "answer" to avoid downvoting.
[EDIT]
Do not answer such old qustions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900