Last post Mar 28, 2018 02:51 PM by PatriceSc
Mar 28, 2018 01:45 AM|MyagiCodes|LINK
I'm using .net 4.0 to insert textbox values into a sql database. Whenever I try to insert single quotes into the database, the values are appearing as '. How do I save single quotes to the database without having the value converted to #39?
Mar 28, 2018 05:46 AM|vahid bakkhi|LINK
please try below code :
string sql = "insert into yourTable (text) " +
"values ('" + textBox.Text.Replace("'", "''") + "')";
Mar 28, 2018 02:00 PM|MyagiCodes|LINK
I've updated the code below but ' is still being saved to the database.
Public Sub AddMessage(ByVal TransactID As String, ByVal Message As String)
If Not String.IsNullOrEmpty(Note) Then
Mar 28, 2018 02:51 PM|PatriceSc|LINK
String methods are returning a new string so at best it would be :
If it doesn't help, you could check the value found in Message using the debugger :
- if you see already ' then it seems the string was encoded at some point but stayed encoded (maybe it was encoded twice so when posted back and decoded you still have this HTML entity in your string)
- if not it happens later and could depend on your database. ? (so having this kind of encoding option looks weird. Maybe an Oracle option we don't have with SQL Server ?)