How to save single quote with different languages in sql server
I am Inserting Malaysian/Korean/Japaneese language in sql server, i am able to save it successfully but my code broken if any word has a single quote (Apostrophe). I tried following way but unable to save it.
SQL Query is following
"Insert into Employee (CountryCode, Address1, Address2)values('" + Program.CountryCode + "',N'" + Address1.Text + "',N'" + Address2.Text)
During debug my query become with data as below.
Insert into Employee (CountryCode, Address1, Address2)values('JP',N'早'上好',N'早上好'')
Replace single['] quote with 2 single quote['']. This will solves your problem and insert a single quote with the data but field should be nvarchar in place of varchar .
Data''s in place of Data''s
First of all thank you so much for all respected comments which leads me towards proper solution, i am writing how i solved.
string add1 = txtAdd1.Text;
string add2 = txtAdd2.Text;
if(!add1.Contains(";"))
{
if(string.isNullOrEmpty(add1) && add1.Contains("'"))
{
add1 = add1.Replace("'", "''");
}
}
if(!add2.Contains(";"))
{
if(string.isNullOrEmpty(add2) && add2.Contains("'"))
{
add2 = add2.Replace("'", "''");
}
}
and i passed add1 and add2 into query as below.
Insert into Employee (CountryCode, Address1, Address2)values('" + Program.CountryCode + "',N'" + add1 + "',N'" + add2)
链接地址: http://www.djcxy.com/p/95694.html