ADO - Open

Option Explicit
Dim objConn As ADODB.Connection

Private Sub cmdOpenEMP_Click()
   
    On Error GoTo ERR_MAIN

    Dim objRS As ADODB.Recordset
   
    Set objConn = New ADODB.Connection
    Set objRS = New ADODB.Recordset
       
    ''1 CONNECT TO THE DATA SOURCE
    If Me.chkOracle Then
        objConn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=yti;" & _
                             "User ID=scott;Password=tiger;"
    Else
        objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                     "Data Source=C:\JPI\11th Batch Training\dbMSAccess.mdb"
    End If
   
    objConn.Open
   
    ''2 OPEN RECORDSET
    With objRS
       
        .Open "EMP", objConn
   
        ''The Recordcount property is used to return the number of records in the recordset.
        'If .RecordCount > 0 Then

            ''MoveFirst - Moves the cursor to the first record in the recordset
            .MoveFirst

            ''When the cursor is pointing at the beginning of the file (BOF),
            ''  it is actually set before the first record.
            ''  The BOF property is set to True when the pointer is at BOF.
            ''The EOF is the opposite of the BOF property.
            ''  When the cursor is pointing at the end of the file (EOF),
            ''  it is actually set after the last record.
            ''  The EOF property is set to True when the record pointer is at EOF.
            Do Until .EOF

                ''Display EMPNO and ENAME
                Debug.Print .Fields("EMPNO").Value & " : " & .Fields("ENAME").Value

                ''MoveNext - Moves the cursor to the next record in the recordset
                .MoveNext
            Loop

            ''Close the recordset
            .Close
        'End If
   
    End With
   
    objConn.Close
    Exit Sub
   
ERR_MAIN:
    MsgBox Err.Number & " : " & Err.Description
End Sub

comment 0 comments:

Post a Comment

Delete this element to display blogger navbar

 
© C.L.S.T.I. Tutorial | Design by Blog template in collaboration with Concert Tickets, and Menopause symptoms
Powered by Blogger