在SQL查询C#QODBC中逃避单引号挣扎

时间:2018-04-05 02:44:04

标签: c# sql select quotes double-quotes

我正在尝试运行包含单引号的SQL查询。我正在使用qodbc,当我试图用单引号成功时:

  1. 使用反斜杠

  2. 使用双引号

  3. 代码:

    string getQBInventory = "SELECT ListId, Name, QuantityOnHand from Item WHERE Name LIKE '"+ "PMI / 8\"X25''" + "%' AND IncomeAccountRefFullName <> 'Job Income' AND isActive <> 0";
    

    知道我做错了吗?

    我正在查询以下内容:

    PMI/8"X25'
    

1 个答案:

答案 0 :(得分:1)

这会对你有所帮助。 CommandType必须为Text

string getQBInventory = "SELECT ListId, Name, QuantityOnHand from Item WHERE Name LIKE ? AND IncomeAccountRefFullName <> ? AND isActive <> ?"

OdbcCommand exe = new OdbcCommand(getQBInventory, conn);
exe.CommandType = CommandType.Text;

exe.Parameters.Add("P1", OdbcType.VarChar).Value = "PMI/8\"X25\'\'";
exe.Parameters.Add("P2", OdbcType.VarChar).Value = "Job Income";
exe.Parameters.Add("P3", OdbcType.Int).Value = 0;
相关问题