Click here to Skip to main content
16,020,249 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
When I use replace function in access query it work fine but when I execute this query in my vb.net program it show error undefined function replace.

Here Is a Query :
SQL
SELECT ShopMaster.ShopId, ShopMaster.ShopName, Replace(ShopName,' ','') AS SearchShopName FROM ShopMaster


This query work fine in access but not through my vb.net program.

I am using vb.net 2008 and access 2007.

Thanks
Rohit Sharma
Posted
Updated 16-Mar-17 21:27pm
v3
Comments
Toniyo Jackson 9-Dec-10 8:00am    
Always use code/query on code block.
rohit_189 9-Dec-10 8:13am    
Thanks ToniyoJackson

Ah. Access.

I believe you will not be able to do this outside of MS Access. Does VB.Net 2008 have the Replace() function and if so, are you using it correctly? I don't program with VB.Net so this is why I ask.

Please note: Access works great when you are doing stuff "in" Access but it is a very hard database to work with as a backend to VB, C#, etc...


I have found that SQL Server (Express) as my backend and Access as my frontend works well and reduces the headaches involved when working with MS Access as the backend.
 
Share this answer
 
Comments
rohit_189 10-Dec-10 0:50am    
Thanks Slacker. I guess you are right that Ms Access function not work right. but due to some technical and hardware limitation from client side i have to use MS Access.
If all you are trying to do is get rid of spaces, why don't you instead use this:
SELECT ShopMaster.ShopId, ShopMaster.ShopName, Trim(ShopMaster.ShopName) AS SearchShopName FROM ShopMaster


If it's not just about extra spaces, you might want to try the iif instead of Replace. (I didn't test with a 2007 access database, so I'm not sure it's still available...)

SELECT ShopMaster.ShopId, ShopMaster.ShopName, iif(ShopName,' ','') AS SearchShopName FROM ShopMaster
 
Share this answer
 
The query works in Access because the Replace function is defined by Access, not by the limited subset of TSQL that the Jet database engine supports.
 
Share this answer
 
v2
Example: To get rid of carriage-returns in your text:

UPDATE OUTFILE05AAA SET MatlDesc =
Replace(Replace(Replace([MatlDesc],Chr(10)," "),Chr(4)," "),Chr(3)," ");
 
Share this answer
 

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



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