Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Errore INSERT su DB MySQL (VB.Net)
Forum - C# / VB.NET - Errore INSERT su DB MySQL (VB.Net)

Avatar
canfra (Normal User)
Newbie


Messaggi: 1
Iscritto: 22/10/2018

Segnala al moderatore
Postato alle 13:11
Lunedì, 22/10/2018
Ciao a tutti,
non riesco a capire perché dopo aver stabilito la connessione con il DB MySQL in fase di INSERT mi restituisce l'errore "Fatal error encountered during command execution".
Utilizzo il Framework 4.6 e ho aggiunto il riferimento MySQL.Data 8.0.12.0
le SELECT funzionano normalmente
Grazie in anticipo per l'aiuto

Questo è il codice VB.Net :
Imports MySql.Data.MySqlClient

Public Class Form1
Dim StringaConnessione As String = "server=127.0.0.1;database=db_prova;user id=root;password=xxxxxxx"
Dim SQL_Comando As String
Dim ConnessioneDB As New MySqlConnection(StringaConnessione)
Dim ComandoSQL As MySqlCommand

Private Sub butWrite_Click(sender As Object, e As EventArgs) Handles butWrite.Click
Dim ccc As String = "Cognome"
Dim nnn As String = "Nome"
Dim ddd As String = "14/12/1967"

SQL_Comando = "INSERT INTO schede (" _
& "Cognome, " _
& "Nome, " _
& "ddn " _
& ") VALUES ( " _
& "@Cognome, " _
& "@Nome, " _
& "@ddn " _
& ")"


ComandoSQL = New MySqlCommand(SQL_Comando, ConnessioneDB)
With ComandoSQL
.CommandText = SQL_Comando
.Connection = ConnessioneDB
.Parameters.Add("@Cognome", MySqlDbType.VarChar).Value = ccc
.Parameters.Add("@Nnome", MySqlDbType.VarChar).Value = nnn
.Parameters.Add("@ddn", MySqlDbType.Date).Value = ddd
End With

Try
ConnessioneDB.Open()

If ComandoSQL.ExecuteNonQuery = 1 Then
MessageBox.Show("INSERT OK")
End If

ConnessioneDB.Close()

Catch errore_di_connessione As MySqlException

MsgBox(“Errore in scrittura DB: ” + errore_di_connessione.Message)
Finally
ConnessioneDB.Dispose()
End Try
End Sub
End Class

Ultima modifica effettuata da canfra il 22/10/2018 alle 13:14
PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6402
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 15:33
Lunedì, 22/10/2018
Scopri l'intruso ....

@Nnome


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2305
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 18:01
Lunedì, 22/10/2018
Testo quotato

Postato originariamente da nessuno:

Scopri l'intruso ....

@Nnome



:rotfl:


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote