VERSION 5.00 Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" Begin VB.Form frmDataConnection Caption = "ADODB database connection" ClientHeight = 4665 ClientLeft = 60 ClientTop = 345 ClientWidth = 7695 LinkTopic = "Form1" ScaleHeight = 4665 ScaleWidth = 7695 StartUpPosition = 3 'Windows Default Begin MSComctlLib.ListView lvwData Height = 3495 Left = 360 TabIndex = 3 Top = 240 Width = 5175 _ExtentX = 9128 _ExtentY = 6165 LabelWrap = -1 'True HideSelection = 0 'False AllowReorder = -1 'True _Version = 393217 ForeColor = -2147483640 BackColor = -2147483643 BorderStyle = 1 Appearance = 1 NumItems = 3 BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} Object.Width = 2540 EndProperty BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} SubItemIndex = 1 Object.Width = 2540 EndProperty BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} SubItemIndex = 2 Object.Width = 2540 EndProperty End Begin VB.CommandButton cmdAll Caption = "Show All" Height = 375 Left = 6360 TabIndex = 2 Top = 1800 Width = 975 End Begin VB.CommandButton cmdStop Caption = "Stop" Height = 495 Left = 6240 TabIndex = 1 Top = 840 Width = 1215 End Begin VB.CommandButton cmdStart Caption = "Connect to Database" Height = 495 Left = 6240 TabIndex = 0 Top = 240 Width = 1215 End Begin VB.Line Line2 X1 = 6240 X2 = 7560 Y1 = 2400 Y2 = 2400 End Begin VB.Line Line1 X1 = 6240 X2 = 7560 Y1 = 1560 Y2 = 1560 End End Attribute VB_Name = "frmDataConnection" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit 'oefening : 'data weergeven in ListView ' requires Microsoft Windows Comůmon Controls 6.0 'xxxxxxxxxxxxxxxxxxxxxxxxxxx 'declareer connectie; 'vereist Microsoft ActiveX Dataobjects 2.6 Library (references) Dim cn As ADODB.Connection 'declareer recordset, globaal zodat alle procedures hem kennen Dim rec As ADODB.Recordset Private Sub cmdStart_Click() 'make database connection Set cn = New ADODB.Connection 'set properties of connection cn.ConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=" & App.Path & "\Biblio.mdb;" 'connectie met database maken cn.Open 'make record set, i.e select data Dim strSQL As String 'to hold an SQL statement Set rec = New ADODB.Recordset strSQL = "select * from Titles" 'set recordset properties With rec .ActiveConnection = cn .Source = strSQL .LockType = adLockOptimistic 'wijze van recordvergrendeling tijdens update .CursorType = adOpenDynamic 'wijze van refresh & navigatie in recordset End With 'recordset openen : de data worden nu opgehaald 'en zijn beschikbaar voor navigatie en output rec.Open 'zie 'close' End Sub Private Sub cmdStop_Click() 'recordset afsluiten en vernietigen rec.Close Set rec = Nothing 'idem voor connectie cn.Close Set rec = Nothing End Sub Private Sub cmdAll_Click() 'alle records dumpen in listview 'variabelen Dim strText As String Dim intFields As Integer Dim i As Integer 'object declarations for listview Dim clmX As ColumnHeader Dim itmX As ListItem 'list view properties : bepaalt weergave , kolommen enz With lvwData .AllowColumnReorder = False .View = lvwReport .HideColumnHeaders = False .LabelEdit = lvwAutomatic .LabelWrap = True End With 'aantal velden bepalen in tabel intFields = rec.Fields.Count - 1 'veldnamen weergeven als column header For i = 0 To intFields Set clmX = lvwData.ColumnHeaders.Add(, , rec.Fields(i).Name) Next i 'data ophalen en dumpen in listbox 'ga naar eerste record rec.MoveFirst 'alle data : loop tot end of file While Not rec.EOF ' data wordt item in list view strText = rec.Fields(0).Value Set itmX = lvwData.ListItems.Add(, , strText) 'volgende velden worden subitems van 1ste veld (itmX) For i = 1 To intFields 'itmX.SubItems(i) = IIf(IsNull(rec.Fields(i).Value), vbNullString, rec.Fields(i).Value) strText = "-" & rec.Fields(i).Value itmX.SubItems(i) = strText Next i 'naar volgende record <<< NIET VERGETEN >>> rec.MoveNext Wend 'recordset afsluiten rec.Close Set rec = Nothing End Sub