views:

203

answers:

2

Hi, I have a .net datatable...from which I am filtering rows using datatable' select function

Assume the datatable as below


Id | Name | Description |


1 | Anish| "sachin's centuary" |


If I search my datatable as...

datatable.select("Description = 'sachin's centuary'")...it is not returning any rows because of the "single quote" in description.

I tried to replace the single quote with double single quote as in sql...but no luck.

Plz help ...

A: 

You most likely have to escape the single quotes within the function call like so:

datatable.select("Description = 'sachin\'s centuary'")

Though you didn't state what language you are using.

aefxx
I am using c#How do I insert "\" before single quote in the string 'sachin's centuary'. I tried Replace function but the string after replace looks same...am not able to see any "\"
Anish Mohan
A: 

In the following blog ...i have seen this solution http://www.marvinpalmer.com/MarvinPalmer/post/Trouble-with-Single-Quotes-and-StringReplace().aspx

public string escapeChar(string strToEsc) { if (strToEsc.IndexOf("'") > -1) {
strToEsc = strToEsc.Replace("'", @"\'"); // notice the addition of the @ symbol } return strToEsc; }

but its not working for me..."'" is getting replaced with "\'" :(

Anish Mohan