J
John Gamble
Hi,
Got a question for you all regarding ADO.NET and single quotes …
I am creating stored procedure parameters, assigning them to a ADO
Command object then executing the Stored Procedure. All works
wonderfully, but when I need to insert the line:
US,Chicago O'Hare Airport-Ord,IL
It complains about the single quote in O'Hare. Now I know ADO.Net is
supposed to handle this for me, but it clearly isn't. I have also
tried escaping it myself using another ' so the string becomes:
US,Chicago O''Hare Airport-Ord,IL
But this generates the same error message below.
Error message:
Line 1: Incorrect syntax near 'Hare'.
Unclosed quotation mark before the character string ',1)'.
..Net SqlClient Data Provider
Code:
DBAccess.DBAccess oDB = new DBAccess.DBAccess();
oDB.SP = "CDR_Add"; // Stored Procedure name
oDB.setConnection();
oDB.setCommand();
SqlParameter oP6 = new SqlParameter("@Location",SqlDbType.VarChar,50);
oP6.Value = "US,Chicago O'Hare Airport-Ord, IL";
oDB.oCommand.Parameters.Add(oP6);
oDB.oConnection.Open();
oDB.oCommand.ExecuteNonQuery();
oDB.close();
oDB = null;
DBAccess is my own wrapper which I use to simplify connections to the
database and ensures that all connections have been closed etc. I've
exposed more of its functionality than is necessary so you can see
what is going on. Let me stress this works perfectly well for strings
that don't have the have the apostrophe. With regard to adding a
parameter to a ADO Command object can anybody seen this behaviour
before?
Thanks in advance
John
Got a question for you all regarding ADO.NET and single quotes …
I am creating stored procedure parameters, assigning them to a ADO
Command object then executing the Stored Procedure. All works
wonderfully, but when I need to insert the line:
US,Chicago O'Hare Airport-Ord,IL
It complains about the single quote in O'Hare. Now I know ADO.Net is
supposed to handle this for me, but it clearly isn't. I have also
tried escaping it myself using another ' so the string becomes:
US,Chicago O''Hare Airport-Ord,IL
But this generates the same error message below.
Error message:
Line 1: Incorrect syntax near 'Hare'.
Unclosed quotation mark before the character string ',1)'.
..Net SqlClient Data Provider
Code:
DBAccess.DBAccess oDB = new DBAccess.DBAccess();
oDB.SP = "CDR_Add"; // Stored Procedure name
oDB.setConnection();
oDB.setCommand();
SqlParameter oP6 = new SqlParameter("@Location",SqlDbType.VarChar,50);
oP6.Value = "US,Chicago O'Hare Airport-Ord, IL";
oDB.oCommand.Parameters.Add(oP6);
oDB.oConnection.Open();
oDB.oCommand.ExecuteNonQuery();
oDB.close();
oDB = null;
DBAccess is my own wrapper which I use to simplify connections to the
database and ensures that all connections have been closed etc. I've
exposed more of its functionality than is necessary so you can see
what is going on. Let me stress this works perfectly well for strings
that don't have the have the apostrophe. With regard to adding a
parameter to a ADO Command object can anybody seen this behaviour
before?
Thanks in advance
John