Search code examples
asp.netsql-servervb.netapostrophe

Error with encoding apostrophe to and from database


I have an html string that is dynamically created server side.

strHTML = "<td><a href""google.com"" onclick=""SaveToDatabase('" + arrString(0) + "','" + arrString(1) + "')""  

The value of arrString(1) is javascript:OpenDoc('ProductManual.pdf','vbShowDoc')

Error Message: Expected ')'

How can I encode this value to save in the database, and decode it when retreving it from the database ?


Solution

  • simple

    you should replace ' to \'

    (C#)

    arrString(0)=arrString(0).replace("'",@"\'")