VB.NET winform INSERTION MYSQL avec 2 tables

Résolu
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. Contributeur
    bonsoir, d'habitude, on fait deux INSERT, un par table.
    1. 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