user2826499
user2826499

Reputation: 121

Replacing Double Quote by Single Quote

I have a GridView where I will display the data in my table. In my table, I have:

FIELD ITEM
=======
Fruit"s
Vegetable"s

That's how I saved it in my table. So in saving, I'm using Replace("'", "\""); but my problem is now how should I display it again in single quote.

This is how I saved it

SQLCMD = "INSERT INTO Table(fldItem) VALUES ('" + _strItem.Replace("'", "\"") + "')";

but when I tried to used it in code-behind:

string _qry = "SELECT Replace(fldItem,'"','''') FROM Table";

There's an error saying

Too many characters in character literal

Upvotes: 0

Views: 1440

Answers (1)

Ullas
Ullas

Reputation: 11566

You need to escape the " with a backslash, \".

So,

string _qry = "SELECT Replace(fldItem,'\"','''') FROM Table";

OR

string _qry = @"SELECT Replace(fldItem,'""','''') FROM Table";

Test

Please check this

Upvotes: 3

Related Questions