MySQL Forums
Forum List  »  Italian

Problema con apostrofi e mysql connector
Posted by: marco zecchi
Date: October 04, 2017 03:48AM

Sto riscontrando un grave problema con MySql, quando utilizzo gli apostrofi nei testi.
Di seguito un esempio di codice che da problemi, con un pò di psiegazioni al seguito


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()



Quando inserisco un testo nel campo txtCodFor, che contiene un apostrofo, il codice va in errore (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, ).

Ho provato anche a fare la sostituzione del testo con doppio apostrofo: txtCodFor.Text.Replace("'", "''") ma non c'è stato nulla da fare.
Inoltre se inserisco un backslash, viene dupplicato in fase di salvataggio.

Ho visto che se tolgo l'opzione "NO_BACKSLASH_ESCAPES" , dal sql_mode in my.ini, tutto funziona correttamente.
Purtroppo io non posso rimuovere questa opzione definitivamente per motivi di compatibilità con un applicazione scritta in VB6 (connessa via ODBC)

Grazie per l'aiuto

Options: ReplyQuote


Subject
Views
Written By
Posted
Problema con apostrofi e mysql connector
812
October 04, 2017 03:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.