Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi ,
I want to save value in SQLServer database which is inserted in textbox if it has singlequote,
I replaced singgle quote using replace("'","''")
but when I am displaying it single quote,it is replaced by double quote
I want to show again it with single quote
I have tried
Replace("'", @"\'")
Replace("'", "\'")
Replace("'", "''")
But not getting proper output
can anyone help me out to solve this
Posted
Comments
ZaneArellano 20-Feb-13 21:37pm    
why do you need to remove the single quote upon saving?
syna syna 21-Feb-13 0:26am    
in sql server it will take single quote to represent string ,so the value I am giving will be changed if I save with single quote
ZaneArellano 21-Feb-13 21:39pm    
in what datatype your saving the data?
how do you write your sql?
i've been saving data with a single qoute but it doesn't change at all.
i'm just a little curious here,pardon me
syna syna 4-Mar-13 6:10am    
when I am Replacing with above scenarios like
Replace(''', '"');
Replace(''', '''');
Replace('\'', '"');

It is getting saved but when I am retrieving value
I am not getting single quote i am getting replaced value

I need solution for this

You need replace single quotes (') with four times single quotes next to each other like ('''')in sql.
 
Share this answer
 
v2
Comments
syna syna 20-Feb-13 2:26am    
why four quotes?
[no name] 20-Feb-13 3:50am    
write this query in ur sql

SELECT '''' this will give u single quote in sql.
syna syna 20-Feb-13 5:44am    
Thank you...
C#
string str = "abc'def";
            string str1 = str.Replace('\'', '"');
            string str2 = str.Replace('"', '\'');
 
Share this answer
 
Comments
syna syna 5-Mar-13 3:53am    
this is also not working when I getting value from database
Asim Mahmood 5-Mar-13 9:28am    
here is one mistake regarding Object but it's working fine here
string str = "abc'def";
string str1 = str.Replace('\'', '"');
string str2 = str.Replace('"', '\'');

and send me your value which you want to replace
Thanks

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