Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Error with apostrophe in VB.net with mySQL connector (no replies)

$
0
0
I'm having problems, with MySQL, with the following code:


Imports MySql.Data.MySqlClient 'LAst version 6.9.9.0 ADO.Net driver for MySQL
Dim commandSQL As MySqlCommand
connMySQL.Open()
commandSQL = connMySQL.CreateCommand
commandSQL.Connection = connMySQL

commandSQL.CommandText = "UPDATE t_tesordacq SET COD_FOR=@COD_FOR WHERE YEAR_DOC = 2017 And NUM_DOC = 123"
With commandSQL.Parameters
.AddWithValue("@COD_FOR", txtCodFor.Text)
End With
commandSQL.ExecuteNonQuery()
commandSQL.Parameters.Clear()

When I insert a text in the txtCodFor field, which contains an apostrophe, the code goes wrong You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near '\'test' WHERE YEAR_DOC = 2017 And NUM_DOC = 123, ).

I also tried replacing the text with double apostrophe: txtCodFor.Text.Replace("'", "''") but there was nothing to do.
Also, if I insert a backslash, it is duplicated!

I've seen that if I remove the "NO_BACKSLASH_ESCAPES" option, from sql_mode in my.ini, everything works correctly.
Unfortunately I can not permanently remove this option for compatibility with a written application in VB6 (ODBC-connected)

Thanks for your help

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>