DataTable.Select strings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to select with a string value containing an embedded ' (single
quote)?
Is there an escape cahracter for this situation?
How can the escape character be inserted?

such as: string filter = "Field = 'John's dog'"
 
Oh

string s = @"John's dog"; //@ is more of global escape for a string, I
like it
or
string s = "John\'s dog"; // not sure on this one!!
 
My problem is the search string already exists in a database so I must
replace the embedded single quotes in the search string in a manner that it
will match the embedded single quote in the dataTable field being searched.
ie:

string filter = string.Format("PLACENAME = '{0}' AND COUNTY = '{1}' AND
COUNTRY = '{2}'",
parishName, county, country);

Where the field PLACENAME contains strings with embedded single quotes. and
the string parishname is accessed from another database table field which
contains corrosponding embedded single quotes.
 
uhmm, this one I did a while back actually long back in VB 5.0 days.. I will
give it a shot, you can try this.

PLACENAME = 'John'''s Dog'
So you have to replace a single quote with a single quote inside 2 single
quotes. You can run a loop to do so, get each occurrence and replace it.

if It don't work, I can see what I have in VB50 archives and get you ..I
might even have the function that did the replace..!

VJ
 
I have found a solution. If I replace the single quote with two single
quotes it works.

Thank you for your help.

Best regards;
 
Back
Top