Undefined function 'Replace' in expression

感情迁移 提交于 2019-12-31 01:46:10

问题


I am having a VB.Net application. I connect it with a MS Access database. Now I have to execute a query. My query is : Update table1 set field1=replace(field1,'|','"')

This query seems to work fine from the query analyzer of the Access database but when I do the same form the VB.Net code it throws me an error stating "Undefined function 'Replace' in expression"

I am using OLEDB connection and command. I am using the "executenonquery" feature.

Can any one help me?


回答1:


Unfortunately when you connect to an Access database from you VB.Net application you aren't using the Access query engine at all. You're using Jet. Some of the functions available to you in Access (such as Replace) aren't available in Jet.

The classic solution is to use a combination of Iif, Instr etc (those are available). Yep, it's not as nice as having Replace to play with but you'll have to learn to do without.




回答2:


The currently-accepted answer to this question is somewhat outdated. Using

Provider=Microsoft.ACE.OLEDB.12.0

the following C# code works just fine:

cmd.CommandText =
    "UPDATE table1 SET field1 = Replace(field1, '|', '\"')";
cmd.ExecuteNonQuery();

In other words, the Replace() function may have caused problems with the older "Jet" OLEDB driver (and perhaps earlier versions of the "ACE" driver) but as of the version for Access 2010 this is no longer an issue.



来源:https://stackoverflow.com/questions/6341465/undefined-function-replace-in-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!