Manipulation BD Access

lionneIAG Messages postés 2 Date d'inscription mardi 25 mars 2008 Statut Membre Dernière intervention 22 avril 2008 - 25 mars 2008 à 19:28
mowaz Messages postés 1 Date d'inscription vendredi 11 avril 2008 Statut Membre Dernière intervention 11 avril 2008 - 11 avril 2008 à 14:57
Salut,
j'arrive à faire une connexion VBNET Access(Office 2003) mais j'ai pas pu manipuler la base(ajout, modification, suppression).
Si vous pouvez m'envoyer le code,ça sera gentil de votre part. 
Merci d'avance

2 réponses

cs_bernardo67 Messages postés 41 Date d'inscription dimanche 28 mai 2006 Statut Membre Dernière intervention 20 janvier 2009
31 mars 2008 à 22:26
Salut,

Cherche "Plasserre" et "access" avec ton copain google, tu trouveras les explications et le code.

Bernardo.
0
mowaz Messages postés 1 Date d'inscription vendredi 11 avril 2008 Statut Membre Dernière intervention 11 avril 2008
11 avril 2008 à 14:57
salut,
voila j'ai un code de connexion a la BD et aussi pour ajouter,modifier et supprimer...

Public Class Form1
    'déclaration de variable
    Public cn As New OleDb.OleDbConnection
    Public cm As New OleDb.OleDbCommand
    Public datasclts As New DataSet
    Public datadpclts As New OleDb.OleDbDataAdapter
    Public datarclts As DataRow
    Public databclts As DataTable


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'connection a la base de donnée
        cn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=c:\clts.mdb"
        cn.Open()
        MsgBox("bien")
        Dim datadpclts As New OleDb.OleDbDataAdapter("select*from tableclts", cn)
        datadpclts.Fill(datasclts, "tableclts")
    End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'button ajouter
        cm.Connection = cn
        datarclts = datasclts.Tables("tableclts").Rows.Add
        cm.CommandText = "insert into tableclts ([code],nom,prenom,adresse)values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
        datadpclts.InsertCommand = cm
        datadpclts.Update(datasclts, "tableclts")
        MsgBox("bien enregistrer")
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'button rechercher
        Dim rep As String
        Dim i As Integer
        Dim trouve As Boolean = False
        databclts = datasclts.Tables("tableclts")
        rep = InputBox("taper le code du client rechercher")
        If rep <> "" Then
            For i = 0 To databclts.Rows.Count - 1
                If databclts.Rows(i).Item("code").ToString Then
                    TextBox1.Text = databclts.Rows(i).Item("code").ToString
                    TextBox2.Text = databclts.Rows(i).Item("nom").ToString
                    TextBox3.Text = databclts.Rows(i).Item("prenom").ToString
                    TextBox4.Text = databclts.Rows(i).Item("adresse").ToString
                    trouve = True
                    Exit For
                End If
            Next
            If trouve = False Then
                MsgBox("client introuvable")
            End If
        End If
    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'button modifier
        datarclts = datasclts.Tables("tableclts").Rows.Add
        cm.Connection = cn        cm.CommandText "Update client SET [code] '" & TextBox1.Text & "', nom = '" & TextBox2.Text & "', prenom = '" & TextBox3.Text & "' where [code] ='" & TextBox1.Text & "'"
        datadpclts.InsertCommand = cm
        datadpclts.Update(datasclts, "tableclts")
        MsgBox(" modification effectuee ")


    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'button supprimer
        datarclts = datasclts.Tables("tableclts").Rows.Add
        cm.Connection = cn
        cm.CommandText = "Delete from tableclts where  [code]= '" & TextBox1.Text & "'"
        datadpclts.InsertCommand = cm
        datadpclts.Update(datasclts, " tableclts ")
        MsgBox(" modification effectuee ")
    End Sub
End Class
0
Rejoignez-nous