Escape character for C#

  • Thread starter Thread starter Brian Conway
  • Start date Start date
B

Brian Conway

I am trying to get my select statement that is in a string variable to work
with alias column names I need a double quote " to go around some of the
aliases, however, they need to have a double quote around them to get the
sql to work correctly, how can you escape them out so that I can get them to
work within the string?

eri.actual_miles_qty AS "Last Odometer"



I dont want to use underscores.
 
Brian Conway said:
I am trying to get my select statement that is in a string variable to work
with alias column names I need a double quote " to go around some of the
aliases, however, they need to have a double quote around them to get the
sql to work correctly, how can you escape them out so that I can get them to
work within the string?

eri.actual_miles_qty AS "Last Odometer"

"eri.actual_miles_qty AS \"Last Odometer\""
 
Brian,

If you are going against SQL server, then you should be using single
quotes, not double.

You probably shouldn't be doing this at all though. You should use
parameterized queries, as they will allow you to just specify the text, and
it will take care of formatting. This also protects you against SQL
injection attacks, which could have a very detrimental affect on your DB.

Take a look at the Parameters property on the SqlCommand, OleDbCommand,
OdbcCommand, OracleCommand classes (depending on which one you use), as this
is what you will use to create your parameterized query.

Hope this helps.
 
Harlan
Well I tried yours that you listed and it still shows it as invalid.

Nick
Its going against an Oracle databse. Since I am using a Datagrid, I wanted
the headers to show up differently. These are parameters that I am making,
just column headings.
 
string MyString = "eri.actual_miles_qty AS \"Last Odometer\"";

This works on my system. Can you create a small snippet that fails to work
and we can take a look at the code in context?

--- Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top