Bonjour,
j'ai un petit souci. Voila mon problème: j'ai un datagridview ou il y a des données. Et en fait je veux insérer une partie de ces données dans une table.
Pour cela je le fait avec une boucle mais seulement la première ligne du datagridview est insérée dans la base de données. Voici le code. Merci d'avance.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Public Sub insertion_ligne_facturebdd(ByVal numero_facture AsInteger) 

  

        'Déclaration de la connexion à la base de données' 
        Dim MaConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=librairie.mdb") 


        Dim Macommande As OleDbCommand = MaConnexion.CreateCommand() 

        Dim i AsInteger 

        Dim j AsInteger 

        j = ajouter_facture.grille.Rows.Count 

        For i = 0 To i = j 


            'Conversion de la quantité en integer' 
            Dim quantite AsInteger 

            quantite = CType(ajouter_facture.grille(3, i).Value.ToString, Integer)
  

            'Conversion du numéro du produit' 
            Dim num_produit AsInteger 

            num_produit = CType(ajouter_facture.grille(0, i).Value.ToString, Integer) 

  

    'Commande avec la requete d'insertion dans la table composer'             Macommande.CommandText = "INSERT INTO composer(num_facture,num_produit,quantité_achetée) VALUES(" & numero_facture & "," & num_produit & "," & quantite & ")  ;" 

            Dim MyDataAdapter AsNew OleDbDataAdapter(Macommande) 

            'On fait appel au dataAdapter puis on ouvre la connexion 
  

            MaConnexion.Open() 


            'on éxécute la commande 
            MyDataAdapter.UpdateCommand = Macommande 

            MyDataAdapter.UpdateCommand.ExecuteNonQuery() 


            Dim Macommande3 As OleDbCommand = MaConnexion.CreateCommand() 

            'Commande avec la requete pour retirer le stock dun produit' 
            Macommande3.CommandText = "UPDATE produit SET stock_actuel=(stock_actuel-" & quantite & ") WHERE num_produit=" & num_produit & ";" 

 
            Dim MyDataAdapter3 AsNew OleDbDataAdapter(Macommande3) 

            'On fait appel au dataAdapter puis on ouvre la connexion 

            'on éxécute la commande 

      MyDataAdapter3.UpdateCommand = Macommande3 

      MyDataAdapter.UpdateCommand.ExecuteNonQuery() 

  

            'et on ferme la connexion 
            MaConnexion.Close() 

        Next 

  

    End Sub