lionneIAG
Messages postés2Date d'inscriptionmardi 25 mars 2008StatutMembreDernière intervention22 avril 2008
-
25 mars 2008 à 19:28
mowaz
Messages postés1Date d'inscriptionvendredi 11 avril 2008StatutMembreDernière intervention11 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
mowaz
Messages postés1Date d'inscriptionvendredi 11 avril 2008StatutMembreDernière intervention11 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