表达式中未定义的功能“替换",是否替换? [英] Undefined function 'Replace' in expression , Replace alternative?
问题描述
如本问题中所述:表达式中未定义的函数替换" ,我因为出现您根本没有使用Access查询引擎"而收到错误表达式中未定义的函数'替换'的错误,但是我该怎么做呢?显然,将Iif和Instr结合使用"是可行的,但我找不到真正用这些替换某些内容的方法.
as read in this question : Undefined function 'Replace' in expression , I'm getting the error "Undefined function 'Replace' in expression" because "you aren't using the Access query engine at all", but what do I use as an alternative ? Apparantly "a combination of Iif, Instr" would work, but I can't find out a way to actually replace something with these.
我只想从值中删除空格,我该怎么做?
All I want is to remove the spaces out of a value, how would I do this?
const string strSql = "SELECT TOP 15 HOOFDGROEP.HOOFDGROEP, SUBGROEP.SUBGROEP, Artikels.*" +
" FROM (Artikels LEFT JOIN HOOFDGROEP ON Artikels.HOOFDGROEPID = HOOFDGROEP.ID)" +
" LEFT JOIN SUBGROEP ON Artikels.SUBGROEPID = SUBGROEP.ID WHERE REPLACE(ArtikelNaam, ' ', '') LIKE '%' + @ArtikelNaam + '%'";
var objCommand = new OleDbCommand(strSql, _objConnection);
objCommand.Parameters.Add("@ArtikelNaam", OleDbType.Char).Value = naamZoeker.Replace(" ", "");
推荐答案
如果下载并安装
然后您可以在OleDbConnection
对象的连接字符串中使用以下内容...
then you can use the following in the connection string for your OleDbConnection
object...
Provider=Microsoft.ACE.OLEDB.12.0
...和Replace()
函数将可用于您的查询.例如,以下代码对我有用:
...and the Replace()
function will be available to your queries. For example, the following code works for me:
using (var conn = new OleDbConnection())
{
conn.ConnectionString =
@"Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=C:\__tmp\testData.accdb;";
conn.Open();
using (var cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText =
"UPDATE Table1 SET ProductType = Replace(ProductType, ' ', '')";
cmd.ExecuteNonQuery();
}
conn.Close();
}
请注意,您需要以与.NET应用程序相同的位数"下载和安装Access数据库引擎版本:32位应用程序需要数据库引擎的32位版本,而64位应用程序需要数据库引擎的64位版本.
Note that you need to download and install the version of the Access Database Engine with the same "bitness" as your .NET application: 32-bit applications require the 32-bit version of the database engine and 64-bit applications require the 64-bit version of the database engine.
这篇关于表达式中未定义的功能“替换",是否替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!