Click here to Skip to main content
16,020,811 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a situation here.
when ever i try to compare any string(containing apostrophe ' eg O'Rielly ) from my application with database, i get an error.
the solution i got for this is to replace apostrophe with double apostrophe
string .replace("'","''")

and it works too but i have many operations where i have to compare with database and it would be hectic to place this code in every operation, is there any other way that helps me call this code snippet(replace) everywhere which deals with string operation.
any suggestions will be appreciated.
thanks in advance.
Posted
Updated 17-Aug-11 19:44pm
v2

1 solution

You can creat an Extension Method like this

C#
public static string ReplaceQuote(this string s)  
{     
return s.Replace("'","''");
} 


And then when you want to replace that wherever you want you can do this.


C#
s.ReplaceQuote();


Hope this Helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900