VB.NET winform INSERTION MYSQL avec 2 tables

Résolu/Fermé
Programming_018 Messages postés 106 Date d'inscription vendredi 13 janvier 2017 Statut Membre Dernière intervention 14 mars 2024 - Modifié le 15 mai 2018 à 18:40
Programming_018 Messages postés 106 Date d'inscription vendredi 13 janvier 2017 Statut Membre Dernière intervention 14 mars 2024 - 15 mai 2018 à 21:52
Bonjour,

Je voudrais créer une possibilité d'ajouter des renseignements dans deux tables différentes sachant que un par exemple c'est des informations de famille et la deuxième table c'est leurs passages.

 Dim ConnexionSQL As New MySqlConnection
        Dim Command As New MySqlCommand
        Dim MySQLAdapter As New MySqlDataAdapter
        Dim DatabaseSet As New DataTable
        Dim Source As New BindingSource
        ConnexionSQL.ConnectionString="server=SERVEUR;userid=UTILISATEUR;password=MDP;database=BDD;"
        ConnexionSQL.Open()
        Dim query As String
        query = "INSERT INTO BDD.FAMILLE,BDD.PASSAGE(FAMILLE.NOM,PASSAGE.DATE) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
        Command = New MySqlCommand(query, ConnexionSQL)
        MySQLAdapter.SelectCommand = Command
        MySQLAdapter.Fill(DatabaseSet)
        DataGridView1.DataSource = DatabaseSet
        MySQLAdapter.Update(DatabaseSet)
        ConnexionSQL.Close()
        Actualisation() 'J'appelle la fonction pour actualiser


cordialement
A voir également:

1 réponse

yg_be Messages postés 22720 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 23 avril 2024 1 476
15 mai 2018 à 21:39
bonsoir, d'habitude, on fait deux INSERT, un par table.
0
Programming_018 Messages postés 106 Date d'inscription vendredi 13 janvier 2017 Statut Membre Dernière intervention 14 mars 2024 7
Modifié le 15 mai 2018 à 21:52
bonsoir d'accord mais du coup le deuxième insert est ce que je peux faire ce qui va suivre ?

Dim ConnexionSQL As New MySqlConnection
        Dim Command As New MySqlCommand
        Dim MySQLAdapter As New MySqlDataAdapter
        Dim DatabaseSet As New DataTable
        Dim Source As New BindingSource
        ConnexionSQL.ConnectionString="server=SERVEUR;userid=UTILISATEUR;password=MDP;database=BDD;"
        ConnexionSQL.Open()
        Dim query As String
        query = "INSERT INTO BDD.FAMILLE(NOM) VALUES ('" & TextBox1.Text & "')"
        Command = New MySqlCommand(query, ConnexionSQL)
        MySQLAdapter.SelectCommand = Command


query = "INSERT INTO BDD.PASSAGE(PASSAGE.DATE) VALUES ('" & TextBox2.Text & "')"

        Command = New MySqlCommand(query, ConnexionSQL)
        MySQLAdapter.SelectCommand = Command

        MySQLAdapter.Fill(DatabaseSet)
        DataGridView1.DataSource = DatabaseSet
        MySQLAdapter.Update(DatabaseSet)
        ConnexionSQL.Close()
        Actualisation() 'J'appelle la fonction pour actualiser
0