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
| Option Explicit
Private cn As ADODB.Connection
Private record As ADODB.Recordset
Private list As ListItem
Public Sub ConsultationListviewSource(ByRef objlistview As Object, ByVal table As String)
cn.Open
record.Open "SELECT * FROM [" & table & "]", cn, adOpenDynamic, adLockOptimistic
If record.Fields.Count = 5 Then
For k = 0 To 4
With objlistview.ColumnHeaders
.Add , , record.Fields(k).Name, objlistview.Width / 2
End With
Next k
record.MoveFirst
While record.EOF = False
Set list = objlistview.ListItems.Add(, , record.Fields(0))
list.SubItems(1) = record.Fields(1)
list.SubItems(2) = record.Fields(2)
list.SubItems(3) = record.Fields(3)
list.SubItems(4) = record.Fields(4)
record.MoveNext
Wend
End If
record.Close
End Sub
Sub login(textusername As Variant, textpassword As Variant)
On Error GoTo erreur
Set cn = New ADODB.Connection
Set record = New ADODB.Recordset
cn.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost\SQLExpress;Initial Catalog=bdd_trigger_salarie;User ID=textusername;Password=textpassword"
cn.Open
MsgBox "bienvenue", vbInformation, "Login"
Exit Sub
erreur:
If Err.Number = -2147217843 Then
MsgBox "nom d'utilisateur et/ou mot de passe incorrect", vbInformation, "Login"
End If
End Sub
Private Sub Class_Terminate()
cn.Close
Set cn = Nothing
Set record = Nothing
End Sub |
Partager