Mettre a jour table Mysql via ODBC
Bonjour à tous et à toutes,
Je réalise un projet perso en utilisant une petite base local en MySQL.
J'arrive a récupérer les données de la manière suivante
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
Public Sub ChargerDonnées()
TableMateriel = DS1.Tables.Add("Materiel")
TableFournisseurs = DS1.Tables.Add("Fournisseurs")
TableMaintenance = DS1.Tables.Add("Maintenance")
TableTravauxType = DS1.Tables.Add("Travauxtype")
Dim Cn As New Odbc.OdbcConnection
Dim Cnstring As String = "Dsn=localhost;uid=root"
Cn.ConnectionString = Cnstring
Dim Admateriel As New Odbc.OdbcDataAdapter(SQLMateriel, Cn)
Dim AdFournisseurs As New Odbc.OdbcDataAdapter(SQLFournisseurs, Cn)
Dim Admaintenance As New Odbc.OdbcDataAdapter(SQLMaintenance, Cn)
Dim AdTravauxType As New Odbc.OdbcDataAdapter(SQLTravauxType, Cn)
Cn.Open()
Admateriel.Fill(TableMateriel)
Admaintenance.Fill(TableMaintenance)
AdTravauxType.Fill(TableTravauxType)
AdFournisseurs.Fill(TableFournisseurs)
Cn.Close()
TableFournisseurs.PrimaryKey = New DataColumn() {TableFournisseurs.Columns("idfournisseurs")}
End Sub |
Ensuite j' utilise un form pour ajouter dans une datatable des données de la manières suivante
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim NRow As DataRow
' Recuperation du dernier ID
Dim DV As DataView = TableMateriel.DefaultView
DV.Sort = "IDMateriel ASC"
Dim ValeurID As Integer = 0
For Each RW As DataRowView In DV
If ValeurID < CInt(RW.Item("IDMateriel")) Then
ValeurID = CInt(RW.Item("IDMateriel"))
End If
Next
Dim NewID As Integer = ValeurID + 1
NRow = TableMateriel.NewRow
NRow(0) = NewID
NRow(1) = TextBox1.Text
NRow(2) = TextBox2.Text
NRow(3) = TextBox3.Text
NRow(4) = TextBox4.Text
NRow(5) = TextBox5.Text
If IDFournisseurtrouve <> 0 Then
NRow(6) = IDFournisseurtrouve
End If
TableMateriel.Rows.Add(NRow)
' Majbase()
End Sub |
Le soucis malgré mes recherche sur internet je n'arrive p as a mettre à jour la base souvent erreur SQL ou parametres je patine autour du truc mais je ne trouve pas la solution, je cherche une exemple clair
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
Public Sub Majbase()
Dim SQLupdate = "UPDATE Materiel"
Dim SQLinsert = "INSERT INTO Materiel (IdMateriel , RéferenceMat , DesignationMat , LieuMat , ModeleMat , IDFournisseur) VALUES (?,?,?,?,?,?)"
Dim Cn As New Odbc.OdbcConnection
Dim Cnstring As String = "Dsn=localhost;uid=root"
Cn.ConnectionString = Cnstring
Dim Ad As New Odbc.OdbcDataAdapter
Ad.UpdateCommand = New Odbc.OdbcCommand(SQLupdate, Cn)
Ad.InsertCommand = New Odbc.OdbcCommand(SQLinsert, Cn)
' parametres sgbd table materiel
Cn.Open()
Ad.Update(TableMateriel)
Cn.Close()
End Sub |
Merci si une personne sait comment faire.