Trayvhon McCall
Trayvhon McCall

Reputation: 11

Struggling with Escaping Single Quotes in SQL Query C# QODBC

I am trying to run a SQL query that includes single quotes. I am using qodbc and when I have tried to succeed with single quotes by:

  1. Using a backslash

  2. Using double single quotes

Code:

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

Any idea what I am doing wrong?

I am querying the following below:

PMI/8"X25'

Upvotes: 1

Views: 316

Answers (1)

Gaurang Dave
Gaurang Dave

Reputation: 4046

This will help you. CommandType must be 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;

Upvotes: 1

Related Questions