bonjour,
j'ai ecrit ce code, mais il y a une erreur dans ma requete et je ne vois pas ou.
Pouvez vous m'aider ?
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
 
 
Imports System.Data.OleDb
 
Public Class frm_ajoutEnc
 
    Private Sub btn_enr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_enr.Click
        Dim maConnexion As OleDbConnection
        Dim maCommande As OleDbCommand
        Dim strConnect As String
        Dim strSql As String
 
        Dim nom As String
        Dim dat As Date
        Dim montant, regle As Decimal
 
        'recupération et cast des données du formulaire
        nom = txt_nom.Text
        dat = txt_date.Text
        montant = Convert.ToDecimal(txt_MT.Text)
        regle = Convert.ToDecimal(txt_reg.Text)
 
        'mise a jour de la base de données
        Try
            'connexion a la base
            strConnect = "Provider='Microsoft.Jet.OLEDB.4.0';Data Source='C:\Documents and Settings\fdefrocourt\Bureau\Caisse\bdd_agroform.mdb';User ID=Admin;Password=;"
            maConnexion = New OleDbConnection(strConnect)
            strSql = "INSERT INTO Encaissement VALUES('Repas','" & dat & "', " & Double.Parse(montant) & ",'" & nom & "'," & Double.Parse(regle) & ")"
            'Creation de l'objet contenant le req puis ouverture de la bdd
            maCommande = New OleDbCommand(strSql, maConnexion)
            maConnexion.Open()
            'execution de la requete
            maCommande.ExecuteNonQuery()
            'fermeture de la connexion
            maConnexion.Close()
 
            MsgBox("Employé ajouté")
 
            txt_nom.Clear()
            txt_date.Clear()
            txt_MT.Clear()
            txt_reg.Clear()
 
        Catch err As System.Data.OleDb.OleDbException
            MessageBox.Show("ERREUR requête ACCESS:" + err.Message)
        Catch err As System.InvalidOperationException
            MessageBox.Show("ERREUR:" + err.Message)
        Catch err As Exception
            MessageBox.Show("ERREUR GRAVE:" + err.Message)
        End Try
    End Sub
End Class
Merci d'avance