Pages

Tuesday, October 22, 2013

Insert a text with single quote (') in MySQL

Scenario:
 
"This is today's example" 
 
You need to insert following text as value into MySQL:
MySQL doesn't allow us to insert single quote ('), so simply use escape characters.
"This is today''s example"
        OR
"This is today\'s example" 

//C#
// if you are using textbox value use String.Replace()
 
 
string str= textbox1.text.Replace("'","''");
        OR 
string str= textbox1.text.Replace("'","\'");

No comments:

Post a Comment