Salut,

Voilà j'ai réalisé, avec des codes pris à droite et à gauche, une D.A.L.

Pour des essais, j'ai:
# Une base avec une table Tbl_Energie (ID_Energie (Auto), Energie)
# Un formulaire avec un DataGridview pour afficher, ajouter, modifier, supprimer, la table
# Un bouton charger,pour afficher les données dans le DataGridview
# Un bouton sauver, pour mettre à jour les données

Dans la DAL:
Pour charger la table
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
 
Public Sub RemplirDataSet(ByVal objDataSet As DataSet, ByVal strNomTable As String, _
                              ByVal strSelect As String, ByVal strInsert As String, _
                              ByVal strUpdate As String, ByVal strDelete As String)
 
        Dim objConnection As DbConnection = Nothing
        Dim objDataAdapter As OleDb.OleDbDataAdapter = Nothing
 
        Try
 
            ' Création de l'objet connexion
            objConnection = GetConnection()
 
            ' Ouverture de la connexion
            objConnection.Open()
 
            objDataAdapter = CreateDataAdapter(CommandType.Text, strSelect, strInsert, strUpdate, strDelete)
            objDataAdapter.FillSchema(objDataSet, SchemaType.Mapped, strNomTable)
            objDataAdapter.Fill(objDataSet, strNomTable)
 
        Finally
            If objConnection.State <> System.Data.ConnectionState.Closed Then
                objConnection.Close()
            End If
 
        End Try
 
    End Sub
Pour sauver les données
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
 
Public Sub MAJDataSet(ByVal objDataSet As DataSet, ByVal strNomTable As String, _
                          ByVal strSelect As String, ByVal strInsert As String, _
                          ByVal strUpdate As String, ByVal strDelete As String)
 
        Dim objConnection As DbConnection = Nothing
        Dim objDataAdapter As OleDb.OleDbDataAdapter = Nothing
 
        'Try
 
        objConnection = GetConnection()
 
        objDataAdapter = CreateDataAdapter(CommandType.Text, strSelect, strInsert, strUpdate, strDelete)
 
        objConnection.Open()
 
        ' UPDATE du dataset
        objDataAdapter.Update(objDataSet, strNomTable)
 
        objConnection.Close()
 
        'Catch ex As Exception
        'MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Stop)
 
        'End Try
 
    End Sub
La fonction CreateDataAdapter
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
75
76
77
 
 Public Function CreateDataAdapter(ByVal commandType As CommandType, ByVal selectStoredProcedure As String, ByVal insertStoredProcedure As String, _
                                                                        ByVal updateStoredProcedure As String, ByVal deleteStoredProcedure As String) As DbDataAdapter
 
        'Déclarations
        Dim dbSelectCommand As DbCommand = Nothing
        Dim dbInsertCommand As DbCommand = Nothing
        Dim dbUpdateCommand As DbCommand = Nothing
        Dim dbDeleteCommand As DbCommand = Nothing
        Dim dbDataAdapter As DbDataAdapter = Nothing
 
        Try
 
            Dim dbConnection As DbConnection = GetConnection()
 
            'Paramétrage de la commande de sélection
            dbSelectCommand = _dbProviderFactory.CreateCommand()
            dbSelectCommand.CommandType = commandType
            dbSelectCommand.Connection = dbConnection
 
            If Not selectStoredProcedure Is Nothing Then
                dbSelectCommand.CommandText = selectStoredProcedure
            Else
                dbSelectCommand.CommandText = ""
            End If
 
            'Paramétrage de la commande d'insertion
            dbInsertCommand = _dbProviderFactory.CreateCommand()
            dbInsertCommand.CommandType = commandType
            dbInsertCommand.Connection = dbConnection
 
            If Not insertStoredProcedure Is Nothing Then
                dbInsertCommand.CommandText = insertStoredProcedure
            Else
                dbInsertCommand.CommandText = ""
            End If
 
            'Paramétrage de la commande de mise à jour
            dbUpdateCommand = _dbProviderFactory.CreateCommand()
            dbUpdateCommand.CommandType = commandType
            dbUpdateCommand.Connection = dbConnection
 
            If Not updateStoredProcedure Is Nothing Then
                dbUpdateCommand.CommandText = updateStoredProcedure
            Else
                dbUpdateCommand.CommandText = ""
            End If
 
            'Paramétrage de la commande de suppression
            dbDeleteCommand = _dbProviderFactory.CreateCommand()
            dbDeleteCommand.CommandType = commandType
            dbDeleteCommand.Connection = dbConnection
 
            If Not deleteStoredProcedure Is Nothing Then
                dbDeleteCommand.CommandText = deleteStoredProcedure
            Else
                dbDeleteCommand.CommandText = ""
            End If
 
            'Paramétrage de l'adaptateur
            dbDataAdapter = _dbProviderFactory.CreateDataAdapter()
            dbDataAdapter.InsertCommand = dbInsertCommand
            dbDataAdapter.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord
            dbDataAdapter.UpdateCommand = dbUpdateCommand
            dbDataAdapter.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord
            dbDataAdapter.DeleteCommand = dbDeleteCommand
            dbDataAdapter.SelectCommand = dbSelectCommand
 
        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Stop)
 
        End Try
 
        'Retour
        Return dbDataAdapter
 
    End Function
Le remplissage de la table dans le dataset fonctionne bien.

J'ajoute une (ou plusieurs) ligne dans le datagridview, et lorsque je clique sur Sauver, j'obtiens cette erreur:
Aucune valeur donnée pour un ou plusieurs des paramètres requis.
sur la ligne
objDataAdapter.Update(objDataSet, strNomTable)

Je vois pas ou sa cloche...

Merci d'avance pour le coup de main

Gdal