Escape single quote in string

  • Thread starter Thread starter DDE
  • Start date Start date
D

DDE

Hi,

wich way can I escape a string sent to an OleDbComman containing single
quote?

Thanks

Dominique
 
Hi,

I think that it depends of the DB engine you are talking to. I would search
on the product documentation first and/or not found I would try escape it
with the same ' , with a " or enclosing the string in [ ]

Hope this help,
 
Hi,

I am not using Parameters in this case, I am just lookin for a method to do
the thing.

Dominique
 
I am not using a constant string but a structure element.

Dominique


Ignacio Machin said:
Hi,

I think that it depends of the DB engine you are talking to. I would search
on the product documentation first and/or not found I would try escape it
with the same ' , with a " or enclosing the string in [ ]

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

DDE said:
Hi,

wich way can I escape a string sent to an OleDbComman containing single
quote?

Thanks

Dominique
 
Typically, if you Do a string.replace and replace the single quote with
double quotes, it will work for most RDBMS systems. This will do it even if
there's no quote present, the replace will just be ignored. I highly
recommend against this type of methodology, but if you are sure this is what
you want to do...

Dim s As String = "O'Brien"

MessageBox.Show(s.Replace("'", "''"))
 
Hi,

At the end you will have to assign the query to OleDbCommand.CommandText ,
this is a string property, this is where you can do the substitution I'm
talking about

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

DDE said:
I am not using a constant string but a structure element.

Dominique


Ignacio Machin said:
Hi,

I think that it depends of the DB engine you are talking to. I would search
on the product documentation first and/or not found I would try escape it
with the same ' , with a " or enclosing the string in [ ]

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

DDE said:
Hi,

wich way can I escape a string sent to an OleDbComman containing single
quote?

Thanks

Dominique
 
Back
Top