VB.NET winform INSERTION MYSQL avec 2 tables

Résolu
Programming_018 Messages postés 108 Date d'inscription   Statut Membre Dernière intervention   -  
Programming_018 Messages postés 108 Date d'inscription   Statut Membre Dernière intervention   -
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

1 réponse

  1. yg_be Messages postés 23437 Date d'inscription   Statut Contributeur Dernière intervention   Ambassadeur 1 588
     
    bonsoir, d'habitude, on fait deux INSERT, un par table.
    0
    1. Programming_018 Messages postés 108 Date d'inscription   Statut Membre Dernière intervention   7
       
      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