C# 如何处理Access SQL表达式中字符串变量的单引号或双引号

C# 如何处理Access SQL表达式中字符串变量的单引号或双引号,c#,ms-access,parameterized-query,C#,Ms Access,Parameterized Query,我用c#写这行代码是为了操作microsoft access数据库 OleDbCommand sComm = new OleDbCommand ("Update TableToBeImport set TextDefault = '" + resxValue + "' WHERE ControlName = '" + resxKey + "'" , c); resxValue和resxKey都是字符串变量 当两个字符串变量很简单时,如“abc”、“xyz”,一切正常,但当一个字符

我用c#写这行代码是为了操作microsoft access数据库

OleDbCommand sComm = new OleDbCommand
  ("Update TableToBeImport set TextDefault = '" + resxValue + "' 
    WHERE ControlName = '" + resxKey + "'" , c);
resxValue
resxKey
都是字符串变量

当两个字符串变量很简单时,如“abc”、“xyz”,一切正常,但当一个字符串变量变得复杂时,在我的例子中,如下所示:

小贴士:

  • 要修复费率计划和rpt错误,请使用“重新处理”

  • 要修复运营商、中继组、交易员错误,请使用“删除并重新插入”

  • 程序抛出错误,当我进行调试时,sComm.CommandText的格式如下:

    更新TableToBeImport set TextDefault='提示:\r\n1。厘定差饷计划 &rpt错误使用“重新处理”\r\n2。要修复运营商、中继组、交易员错误, 使用“删除并重新插入”,其中ControlName='frmCDRQuery.label7.Text'


    我知道在c#中,我可以在字符串变量之前使用
    @
    ,因此其中的任何转义字符都将被忽略。但是在ACCESS中,我怎样才能得到相同的结果呢?

    这对您有用吗

    var resxValue = ""; // obviously this will be whatever the type and value that is required
    var resxKey = ""; // obviously this will be whatever the type and value that is required
    
    // I am assuming here that you are already programming with a `using` statement
    using (OleDbConnection c = new OleDbConnection(""))
    {
        using (OleDbCommand sComm = new OleDbCommand("UPDATE TableToBeImport SET TextDefault = @p0 WHERE ControlName = @p1", c))
        {
            sComm.Parameters.Add(new OleDbParameter("@p0", resxValue));
            sComm.Parameters.Add(new OleDbParameter("@p1", resxKey));
    
            // rest of your code here E.G., sComm.ExecuteNonQuery();
        }
    }
    

    这对你有用吗

    var resxValue = ""; // obviously this will be whatever the type and value that is required
    var resxKey = ""; // obviously this will be whatever the type and value that is required
    
    // I am assuming here that you are already programming with a `using` statement
    using (OleDbConnection c = new OleDbConnection(""))
    {
        using (OleDbCommand sComm = new OleDbCommand("UPDATE TableToBeImport SET TextDefault = @p0 WHERE ControlName = @p1", c))
        {
            sComm.Parameters.Add(new OleDbParameter("@p0", resxValue));
            sComm.Parameters.Add(new OleDbParameter("@p1", resxKey));
    
            // rest of your code here E.G., sComm.ExecuteNonQuery();
        }
    }