[ADODB] Datenzugriff

Dim DBRecordset As New ADODB.Recordset

DBRecordset.Open("Gebaeude", DBConnection, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)

oder

With DBRecordset
     .ActiveConnection = DBConnection
     .CursorLocation = ADODB.CursorLocationEnum.adUseClient
     .LockType = ADODB.LockTypeEnum.adLockOptimistic
     .Open("SELECT ID, Bezeichnung FROM Gebaeude")
End With
  • allg. Zugriff auf Feldelemente
Dim h As Integer
h = DBRecordset.Fields!ID.Value 'unsauber
h = DBRecordset.Fields.Item(0).Value ' per Index
h = DBRecordset.Fields("ID").Value 'Spaltenname
  • Daten per Schleife aus dem DBRecordset auslesen
While (Not DBRecordset.EOF)
   sXMLResult = DBRecordset.Fields("ID").Value
   DBRecordset.MoveNext()
End While

oder
   
For i = 0 To DBRecordset.RecordCount - 1
   sXMLResult = DBRecordset.Fields("ID").Value
   DBRecordset.MoveNext()
Next i
  • und das Schließen des DBRecordset nicht vergessen
DBRecordset.Close()

Schreibe einen Kommentar