Visual Studio .NET - insert from html editor - Asked By bretto kumar A on 15-Jul-08 03:13 AM


i am using a htmleditor

it has a problem while i am inserting the values into database like

if i am using ( ' ) single quates in my editing content the database returen a error

otherwise those contents are can be stored

what i have to do too over come this problem

please help me 

try this... - Vasanthakumar D replied to bretto kumar A on 15-Jul-08 03:16 AM


its always good to use Server.HtmlEncode and  Server.HtmlDecode while using html editor...

while insert the values into database use...


while retrive from database use



Single Quote - mv ark replied to bretto kumar A on 15-Jul-08 03:45 AM

The solution for this is to replace Single Quote character with two Single Quote characters using the  Replace function.

For example, replace your existing INSERT query with something like this -
"INSERT INTO Titles (title_id, title)" & _
" VALUES('" & txtTitleID.Text.ToString & "', '" & Replace(txtTitle.Text.ToString, "'", "''") & "')"

Convert single quotes character into some other character - santhosh kumar replied to bretto kumar A on 15-Jul-08 03:55 AM

    When storing in the database convert single quotes into some other character and when u retrieve it replace that character with the single quote..

This doesn't offer much performance .. however server.Encode and server.Decode offer hight performance


try this - sri sri replied to bretto kumar A on 15-Jul-08 04:37 AM
try the below query for inserting

query = "insert into employee (name,age) values ('" + txtName.Text.Replace("'","''") + "'," +txtAge.Text + " )"
it may help u - Web Star replied to bretto kumar A on 15-Jul-08 04:39 AM

If you’re creating HTML, SGML, and XML directly, perhaps using a text editor or writing a program, always use “decimal numeric character references” for curling single and double quote characters (these marks are called “smart quotes,” “curly quotes,” “curled quotes,” “curling quotes,” or “curved quotes”). In other words, for left and right double quotation marks, use “ and ” - and for left and right single quotation marks (and apostrophes), use ‘ and ’ - and you’ll be glad you did. This approach complies with all international standards, and works essentially everywhere

simple solution - Nagaraj muthuchamy replied to bretto kumar A on 15-Jul-08 05:13 AM


I have feaced the similar problem in my earlier days. Its prettry simple, The problem  is with the Database. When you Insert the text or Varchar into data base, the value must be enclosed with in single quotes.

In your case, I think, You have written a ad-hoc query to insert the text. If the text has single quote, the database takes the text between first two single quotes as value. Actual closing quote is some where.  Then the rest of the text is considered as another parameter or value. This is the reason for this error.

You can solve it by replacing the ' with '' (Single quote with two single quotes.), and you can use regular expressions also ,

Solution for your problem please check it - zafar iqbal replied to bretto kumar A on 15-Jul-08 05:46 AM

if you are inserting Text value in your database then you will have to convert first into Text of HTML Text::

// Cnvert HTML Text to Text First Before Inserting In database.

// Use the following code for convert

lblText.Text =System.Text.RegularExpressions.Regex.Replace(txtHtmlText.Text, "/<[^>]*>/g","");

in the above code "txtHtmlText.Text" is your Body of HtmlText.

I think this will help you.


Zafar Iqbal