Not able to escape apostrophe/special characters in parameterized query

RESOLVED: The data was being read from a Gridview which had the html encoding. The solution was the following... Dim Sht_Text As String = HttpUtility.HtmlDecode(row.Cells.Item(0).Text)

I am trying to prevent from having to escape apostrophes and other special characters in my string variables by using a parameterized query with an OleDbConnection. I have all of the parameters in the same order, the insert is working, it just does not maintain the characters. I keep getting those pesky html codes. Any help would be appreciated. I am trying to insert into an Access db from a web pages. As I mentioned, its working, just not the special characters.

Here's the code:

Dim pConn As New OleDb.OleDbConnection pConn = New OleDbConnection(cb.ConnectionString)  
Dim SqlString As String = "INSERT INTO Strings (Mlt_String_ID, Lng_ID, Strg_Name, Sht_Text, Lng_Text, Alt_Text) Values (?, ?, ?, ?, ?, ?)"  

Using cmd As New OleDbCommand(SqlString, pConn)     
    cmd.CommandType = CommandType.Text     
    cmd.Parameters.AddWithValue("@Mlt_String_ID", Mlt_String_ID)
    cmd.Parameters.AddWithValue("@Lng_ID", Lng_ID)
    cmd.Parameters.AddWithValue("@Strg_Name", Strg_Name)
    cmd.Parameters.AddWithValue("@Sht_Text", Sht_Text)
    cmd.Parameters.AddWithValue("@Lng_Text", Lng_Text)
    cmd.Parameters.AddWithValue("@Alt_Text", Alt_Text)

    pConn.Open()
    cmd.ExecuteNonQuery()
    pConn.Close()
End Using 

Updated example: This is directly from the access table after Insert.

String_ID String_Name  Long_Text  Short_Text  Alternate_Text Multi_String_ID Lang

993       U_°C_fr °C    °C     °C        651             fr

652       U_°C_jp      °C         °C          °C             651             jp

651       U_°C         °C         °C          °C             651             en

jp and en records already existed, the insert of fr record pushes the html codes for the small circle which represents the degree symbol. Happens for all other special characters as well.

Answers


RESOLVED: The data was being read from a Gridview which had the html encoding. The solution was the following... Dim Sht_Text As String = HttpUtility.HtmlDecode(row.Cells.Item(0).Text)


Need Your Help

Parameter is not valid - error when sending a bitmap via TCP with C#

c# winforms bitmap file-transfer

I have a file transfer program. The program (Client) does following operations to send a bitmap via TCP socket: get screenshot -> grab Bitmap from memory -> convert to stream -> send

How to test Framework if Unit tests are in separate assembly?

.net unit-testing nunit integration-testing

I have assembly with my framework and assembly with tests. But I need to test internal classes or substitute some services.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.