philo_neo | bonsoir,
je développe une application VB dot NET 2012 ultimate sur Mysql, pour les requetes SELECT et DELETE tout ce passent bien, mais pour les requetes INSERT et UPDATE je suis obliger de faire de la requete parametres !
voici le code pour la requete INSERT
Code :
- '*************** insert client *************
- Dim northwindConnection As New MySqlConnection(SQL_CONNECTION_STRING)
- Dim SqlConnection As MySqlConnection
- SqlConnection = New MySqlConnection()
- 'SqlConnection.ConnectionString = (SQL_CONNECTION_STRING)
- 'SQLConnection.Open()
- Dim sqlCommand As New MySqlCommand
- Dim str_carSql As String
- 'Dim strsql As String
- Dim myCommand As MySqlCommand
- 'Dim northwindConnection As New MySqlConnection(SQL_CONNECTION_STRING)
- ' Try
- Dim num As Integer
- Dim code_cl As String
- Dim raison_sociale As String
- Dim code_postal As String
- Dim ville As String
- Dim immat_tva As String
- Dim regime_tva As String
- Dim date_creation As Date
- Dim date_modif As Date
- Dim tiers_mi_sommeil As String
- Dim pays As String
- Dim adresse1 As String
- Dim adresse2 As String
- Dim adresse3 As String
- Dim text_lib_tiers1 As String
- Dim text_lib_tiers2 As String
- Dim text_lib_tiers3 As String
- Dim tiers_bloque As String
- num = Convert.ToInt32(Me.TextBox20.Text)
- code_cl = Trim(Me.TextBox3.Text)
- raison_sociale = Trim(Me.TextBox4.Text)
- code_postal = Trim(Me.TextBox5.Text)
- ville = Trim(Me.TextBox6.Text)
- immat_tva = Trim(Me.TextBox7.Text)
- regime_tva = Trim(Me.TextBox8.Text)
- date_creation = Convert.ToDateTime(TextBox9.Text).ToString("yyyy-MM-dd" )
- ' date_creation = Convert.ToDateTime(Me.TextBox9.Text)
- date_modif = Convert.ToDateTime(TextBox10.Text).ToString("yyyy-MM-dd" )
- ' date_modif = Convert.ToDateTime(Me.TextBox10.Text)
- tiers_mi_sommeil = Trim(Me.TextBox11.Text)
- pays = Trim(Me.TextBox12.Text)
- adresse1 = Trim(Me.TextBox13.Text)
- adresse2 = Trim(Me.TextBox14.Text)
- adresse3 = Trim(Me.TextBox15.Text)
- text_lib_tiers1 = Trim(Me.TextBox16.Text)
- text_lib_tiers2 = Trim(Me.TextBox17.Text)
- text_lib_tiers3 = Trim(Me.TextBox18.Text)
- tiers_bloque = Convert.ToString(Trim(Me.TextBox19.Text))
- str_carSql = "insert into tbl_client (code_cl, raison_sociale, code_postal, ville, immat_tva, regime_tva, date_creation, date_modif, tiers_mi_sommeil, pays, adresse1, adresse2, adresse3, text_lib_tiers1,text_lib_tiers2,text_lib_tiers3, tiers_bloque ) values (?p_code_cl,?p_raison_sociale,?p_code_postal,?p_ville,?p_immat_tva,?p_regime_tva,?p_date_creation,?p_date_modif,?p_tiers_mi_ensommeil,?p_pays,?p_adresse1,?p_adresse2,?p_adresse3,?p_text_libtiers1,?p_text_libtiers2,?p_text_libtiers3,?p_tiers_bloque )"
- ' strsql = "update tlb_client set code_cl, raison_sociale, code_postal, ville, immat_tva, regime_tva, date_creation, date_modif, tiers_mi_sommeil, pays, adresse1, adresse2, adresse3, text_lib_tiers1,text_lib_tiers2,text_lib_tiers3, tiers_bloque ) values (?p_code_cl,?p_raison_sociale,?p_code_postale,?p_ville,?p_immat_tva,?p_regime_tva,?p_date_creation,?p_date_modif,?p_tiers_mi_ensommeil,?p_pays,?p_adresse1,?p_adresse2,?p_adresse3,?p_text_libtiers1,?p_text_libtiers2,?p_text_libtiers3,?p_tiers_bloque, where idtbl_client= 1"
- myCommand = New MySqlCommand(str_carSql, northwindConnection)
- myCommand.Connection = northwindConnection
- myCommand.CommandText = str_carSql
- myCommand.Connection.Open()
- With myCommand.Parameters
- .Add(New MySqlParameter("?p_code_cl", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_raison_sociale", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_code_postale", MySqlDbType.Int32, 12))
- .Add(New MySqlParameter("?p_ville", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_immat_tva", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_regime_tva", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_date_creation", MySqlDbType.Date, 45))
- .Add(New MySqlParameter("?p_date_modif", MySqlDbType.Date, 45))
- .Add(New MySqlParameter("?p_tiers_mi_sommeil", MySqlDbType.VarChar, 1))
- .Add(New MySqlParameter("?p_pays", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_adresse1", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_adresse2", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_adresse3", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_text_lib_tiers1", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_text_lib_tiers2", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_text_lib_tiers3", MySqlDbType.VarChar, 45))
- .Add(New MySqlParameter("?p_tiers_bloque", MySqlDbType.VarChar, 1))
- End With
- 'Attribution des valeurs aux paramètres
- With myCommand
- ' .Connection = SqlConnection
- ' .CommandText = str_carSql
- .Parameters("?p_code_cl" ).Value = code_cl
- .Parameters("?p_raison_sociale" ).Value = raison_sociale
- .Parameters("?p_code_postale" ).Value = code_postal
- .Parameters("?p_ville" ).Value = ville
- .Parameters("?p_immat_tva" ).Value = immat_tva
- .Parameters("?p_regime_tva" ).Value = regime_tva
- .Parameters("?p_date_creation" ).Value = date_creation
- .Parameters("?p_date_modif" ).Value = date_modif
- .Parameters("?p_tiers_mi_sommeil" ).Value = tiers_mi_sommeil
- .Parameters("?p_pays" ).Value = pays
- .Parameters("?p_adresse1" ).Value = adresse1
- .Parameters("?p_adresse2" ).Value = adresse2
- .Parameters("?p_adresse3" ).Value = adresse3
- .Parameters("?p_text_lib_tiers1" ).Value = text_lib_tiers1
- .Parameters("?p_text_lib_tiers2" ).Value = text_lib_tiers2
- .Parameters("?p_text_lib_tiers3" ).Value = text_lib_tiers3
- .Parameters("?p_tiers_bloque" ).Value = tiers_bloque
- End With
- myCommand.ExecuteNonQuery()
- myCommand.Connection.Close()
- ' Catch ex As Exception
- ' Return False
- ' MsgBox("Error occured: Could not insert record" )
- ' End Try
|
le debugger pointe sur le " myCommand.ExecuteNonQuery()"
comprens pas l'erreur Cdlt Philippe
|