A voir également:
- Connexion base de données access avec VB.net
- Gmail connexion - Guide
- Formules excel de base - Guide
- Hotmail connexion - Guide
- Coco.fr connexion ✓ - Forum Réseaux sociaux
- En raison d'un nombre important d'échec de connexion snapchat ✓ - Forum Snapchat
4 réponses
sway-yazen
Messages postés
128
Date d'inscription
mardi 14 octobre 2008
Statut
Membre
Dernière intervention
18 octobre 2011
54
8 mai 2009 à 04:08
8 mai 2009 à 04:08
voilà un exemple de connexion tu peux l'utiliser dans ton projet ..
Imports System.Data.OleDb
'////////////////////////MODULE FONCTION ACCESS////////////////
Module bdaccess
Dim MyConnection As New System.Data.OleDb.OleDbConnection()
'procédure de connection a une bd access
Public Sub connection(ByVal nombd As String)
Try
MyConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & nombd
MyConnection.Open()
Catch ex As Exception
MessageBox.Show("Impossible d'établir la connection à la base." & ex.Message)
End Try
End Sub
'deconenction de la base
Public Sub deconnection()
Try
MyConnection.Close()
Catch ex As Exception
MessageBox.Show("Impossible d'établir la connection à la base." & ex.Message)
End Try
End Sub
Public Function access(ByVal requetesql As String) As DataSet
Dim MyAdapter As OleDbDataAdapter = New OleDbDataAdapter()
Dim MyDataSet As DataSet = New DataSet("MesDonnées")
Dim StrConnect As String
Dim MyCommand As OleDbCommand
Dim requete As String
Try
MyCommand = New OleDbCommand(requetesql, MyConnection)
MyAdapter.SelectCommand = MyCommand
MyDataSet.Clear()
MyAdapter.Fill(MyDataSet, "fichier")
'A ce niveau les donnes résultantes de la requete
'se trouvent dans => MyDataSet.Tables(0)
Return MyDataSet
Catch ex As Exception
MessageBox.Show("Impossible d'établir la connection à la base." & ex.Message)
End Try
End Function
End Module
Imports System.Data.OleDb
'////////////////////////MODULE FONCTION ACCESS////////////////
Module bdaccess
Dim MyConnection As New System.Data.OleDb.OleDbConnection()
'procédure de connection a une bd access
Public Sub connection(ByVal nombd As String)
Try
MyConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & nombd
MyConnection.Open()
Catch ex As Exception
MessageBox.Show("Impossible d'établir la connection à la base." & ex.Message)
End Try
End Sub
'deconenction de la base
Public Sub deconnection()
Try
MyConnection.Close()
Catch ex As Exception
MessageBox.Show("Impossible d'établir la connection à la base." & ex.Message)
End Try
End Sub
Public Function access(ByVal requetesql As String) As DataSet
Dim MyAdapter As OleDbDataAdapter = New OleDbDataAdapter()
Dim MyDataSet As DataSet = New DataSet("MesDonnées")
Dim StrConnect As String
Dim MyCommand As OleDbCommand
Dim requete As String
Try
MyCommand = New OleDbCommand(requetesql, MyConnection)
MyAdapter.SelectCommand = MyCommand
MyDataSet.Clear()
MyAdapter.Fill(MyDataSet, "fichier")
'A ce niveau les donnes résultantes de la requete
'se trouvent dans => MyDataSet.Tables(0)
Return MyDataSet
Catch ex As Exception
MessageBox.Show("Impossible d'établir la connection à la base." & ex.Message)
End Try
End Function
End Module
met ce code dans la chaine de connection et ça va marcher
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=le lien de la base .mdb "
et bonne courage
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=le lien de la base .mdb "
et bonne courage
net_papy
Messages postés
1021
Date d'inscription
lundi 7 novembre 2005
Statut
Membre
Dernière intervention
19 novembre 2016
103
24 sept. 2007 à 00:16
24 sept. 2007 à 00:16
vois un peu ceci
connexion access visual basic
connexion access visual basic
J'ai besoin de votre aide
slt, je suis débitante et c pas mon spécialité, j'ai un problème en mon projet de stage pfe je besoin de liée le code vb 2010 avec base de données access puis le afficher dans un datagridview
j'ai besoin de vos aides
c mon numéro : 22488482
le projet est : un système d'affichage de l'état des machines (pannes ou non) voila un exemple de code d'une machine si vous avez des remarques les posez et merci
le fichier oeeui.vsr est le fichier qui contient les états de machines a travers des codes oee, donc "fichier existe --> lire ligne 5 de codeoee --> lire les de caractère de code D1 jusqu'à F1"
Public Class Form2
Dim CString, BString, AString As String
Dim nommachine
Dim fich As Boolean
Dim a477tps As Object
Dim Dmarie As Boolean
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
a477tps = Now
Timer2.Start()
End Sub
Private stopwatch1 As New Stopwatch
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim elapsed As TimeSpan = Me.stopwatch1.Elapsed()
Label8.Text = String.Format("{0:00}:{1:00}:{2:00}", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds)
End Sub
Private stopwatch2 As New Stopwatch
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim elapsed As TimeSpan = Me.stopwatch2.Elapsed()
Label10.Text = String.Format("{0:00}:{1:00}:{2:00}", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If CString IsNot Nothing Then
Timer1.Start()
Me.stopwatch1.Start()
Timer3.Start()
Me.stopwatch2.Start()
End If
fich = System.IO.Directory.Exists("E:\kmmac045").ToString
If fich = True Then
nommachine = "Alpha 477"
ElseIf fich = False Then
nommachine = "la machine ne pas trouver"
End If
Dmarie = My.Computer.FileSystem.FileExists("E:\kmmac045\d$\vsr\data\oeeui.vsr").ToString
If Dmarie = True Then
Dim Lines() As String = IO.File.ReadAllLines("E:\kmmac045\d$\vsr\data\oeeui.vsr")
AString = Lines(5)
BString = AString.Substring(8, 2)
If BString = "D1" Then
CString = "D1"
ElseIf BString = "D2" Then
CString = "D2"
ElseIf BString = "D3" Then
CString = "D3"
ElseIf BString = "D4" Then
CString = "D4"
ElseIf BString = "D5" Then
CString = "D5"
ElseIf BString = "D6" Then
CString = "D6"
ElseIf BString = "E1" Then
CString = "E1"
ElseIf BString = "F1" Then
CString = "F1"
End If
If CString IsNot Nothing Then
Label1.Text = "Temps de panne"
Label2.Text = a477tps
Label3.Text = "Machines"
Label4.Text = nommachine
Label5.Text = "Codes oee"
Label6.Text = CString
Label7.Text = "Période de panne"
Label9.Text = "Période total des arrêts"
ElseIf CString Is Nothing Then
Label1.Text = "Temps de panne"
Label2.Text = a477tps
Label3.Text = "Machines"
Label4.Text = nommachine
Label5.Text = "Codes oee"
Label6.Text = " "
Label7.Text = "Période de panne"
Label8.Text = "00:00:00"
Me.stopwatch1.Reset()
End If
ElseIf Dmarie = False Then
Label1.Text = "Temps de panne"
Label2.Text = a477tps
Label3.Text = "Machines"
Label4.Text = nommachine
Label5.Text = "Codes oee"
Label6.Text = CString
Label7.Text = "Période de panne"
Me.stopwatch1.Reset()
Label8.Text = "00:00:00"
Label9.Text = "Période total des arrêts"
Timer3.Stop()
Me.stopwatch2.Stop()
End If
End Sub
j'ai besoin de vos aides
c mon numéro : 22488482
le projet est : un système d'affichage de l'état des machines (pannes ou non) voila un exemple de code d'une machine si vous avez des remarques les posez et merci
le fichier oeeui.vsr est le fichier qui contient les états de machines a travers des codes oee, donc "fichier existe --> lire ligne 5 de codeoee --> lire les de caractère de code D1 jusqu'à F1"
Public Class Form2
Dim CString, BString, AString As String
Dim nommachine
Dim fich As Boolean
Dim a477tps As Object
Dim Dmarie As Boolean
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
a477tps = Now
Timer2.Start()
End Sub
Private stopwatch1 As New Stopwatch
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim elapsed As TimeSpan = Me.stopwatch1.Elapsed()
Label8.Text = String.Format("{0:00}:{1:00}:{2:00}", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds)
End Sub
Private stopwatch2 As New Stopwatch
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim elapsed As TimeSpan = Me.stopwatch2.Elapsed()
Label10.Text = String.Format("{0:00}:{1:00}:{2:00}", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If CString IsNot Nothing Then
Timer1.Start()
Me.stopwatch1.Start()
Timer3.Start()
Me.stopwatch2.Start()
End If
fich = System.IO.Directory.Exists("E:\kmmac045").ToString
If fich = True Then
nommachine = "Alpha 477"
ElseIf fich = False Then
nommachine = "la machine ne pas trouver"
End If
Dmarie = My.Computer.FileSystem.FileExists("E:\kmmac045\d$\vsr\data\oeeui.vsr").ToString
If Dmarie = True Then
Dim Lines() As String = IO.File.ReadAllLines("E:\kmmac045\d$\vsr\data\oeeui.vsr")
AString = Lines(5)
BString = AString.Substring(8, 2)
If BString = "D1" Then
CString = "D1"
ElseIf BString = "D2" Then
CString = "D2"
ElseIf BString = "D3" Then
CString = "D3"
ElseIf BString = "D4" Then
CString = "D4"
ElseIf BString = "D5" Then
CString = "D5"
ElseIf BString = "D6" Then
CString = "D6"
ElseIf BString = "E1" Then
CString = "E1"
ElseIf BString = "F1" Then
CString = "F1"
End If
If CString IsNot Nothing Then
Label1.Text = "Temps de panne"
Label2.Text = a477tps
Label3.Text = "Machines"
Label4.Text = nommachine
Label5.Text = "Codes oee"
Label6.Text = CString
Label7.Text = "Période de panne"
Label9.Text = "Période total des arrêts"
ElseIf CString Is Nothing Then
Label1.Text = "Temps de panne"
Label2.Text = a477tps
Label3.Text = "Machines"
Label4.Text = nommachine
Label5.Text = "Codes oee"
Label6.Text = " "
Label7.Text = "Période de panne"
Label8.Text = "00:00:00"
Me.stopwatch1.Reset()
End If
ElseIf Dmarie = False Then
Label1.Text = "Temps de panne"
Label2.Text = a477tps
Label3.Text = "Machines"
Label4.Text = nommachine
Label5.Text = "Codes oee"
Label6.Text = CString
Label7.Text = "Période de panne"
Me.stopwatch1.Reset()
Label8.Text = "00:00:00"
Label9.Text = "Période total des arrêts"
Timer3.Stop()
Me.stopwatch2.Stop()
End If
End Sub
31 mai 2009 à 14:19
14 sept. 2010 à 05:54
car on a deja importer le package
22 oct. 2011 à 21:57
merci ton code est correct c'est parfis vraiment merci à vous.
19 nov. 2011 à 17:17
(Outre 2 variables inutilisées dans la fonction (StrConnect) et (requete)
End Function est souligné et le message suivant s'affiche :
Avertissement 1 : La fonction 'access' ne retourne pas une valeur pour tous les chemins de code. Une exception: de référence null peut se produire au moment de l'exécution lorsque le résultat est utilisé.
Débutant en VB 2010 (ex développeur en VB6) je suis un peu paumé...
J'ai bien pigé comment passer le chemin d'accès pour se connecter à la base depuis une Form Ex :
Dim CheminBase As String
CheminBase = "C:\_DATA\BASE.mdb"
Call connection(CheminBase)
En revanche, je suis paumé pour créer le passage des paramètres à la fonction (qui pose un PB en VB 2010 Express) depuis la Form ???
DataSet
OleDbDataAdapter
OleDbCommand
On fait QUOI avec depuis la Form ???
Comment fait-on pour récupérer dans un DataGridView1 un truc du genre :
Select *.* Where TABLE = MaTable FROM Champ MACHIN = `Truc' ORDER BY `NOM ASC
Merci de votre aide.
20 nov. 2011 à 23:32