Die Vorgehensweise zum Erstellen eines ADO-Recordsets ist wie folgt: Dim oRs As ADODB.Recordset Set oRs = New ADODB.Recordset With oRs .CursorLocation = ... .Open "SQL-Abfragestring", oConn, adOpenDynamic, adLockOptimistic End With Das sind also jedesmal mindestens 5 Zeilen Code. Warum eigentlich nicht diese Zeilen in einer gesonderte öffentliche Funktion kapseln? Dann benötigt man zukünftig nur noch eine einzige Codezeile zum Erstellen des Recordsets! ' ADO-Recordset erstellen Public Function dbOpenRecordset(oConn As ADODB.Connection, _ ByVal sSQL As String, _ Optional ByVal CursorType As ADODB.CursorTypeEnum = adOpenDynamic, _ Optional ByVal LockType As ADODB.LockTypeEnum = adLockOptimistic, _ Optional ByVal CursorLocation As ADODB.CursorLocationEnum = adUseClient) _ As ADODB.Recordset Set dbOpenRecordset = New ADODB.Recordset With dbOpenRecordset .CursorLocation = CursorLocation .Open sSQL, oConn, CursorType, LockType End With End Function Aufrufbeispiel Dim oRs As ADODB.Recordset Set oRs = dbOpenRecordset(oConn, "SELECT * FROM Tabelle") 17.07.07: Erweiterung (von Carl-Rainer Zeiss) ' ADO-Recordset erstellen Public Function dbOpenRecordset(oConn As ADODB.Connection, _ ByVal sSQL As String, _ Optional ByVal CursorType As ADODB.CursorTypeEnum = adOpenDynamic, _ Optional ByVal LockType As ADODB.LockTypeEnum = adLockOptimistic, _ Optional ByVal CursorLocation As ADODB.CursorLocationEnum = adUseClient) _ As ADODB.Recordset ' Falls kein "SELECT..." im SQL-String angegeben, ' autom. ergänzen If Instr(1, sSQL, "select", vbTextCompare) = 0 Then sSQL = "SELECT * FROM " & sSQL End If Set dbOpenRecordset = New ADODB.Recordset With dbOpenRecordset .CursorLocation = CursorLocation .Open sSQL, oConn, CursorType, LockType End With End Function Aufrufbeispiel: Dim oRs As ADODB.Recordset Set oRs = dbOpenRecordset(oConn, "Tabelle") Dieser Tipp wurde bereits 31.821 mal aufgerufen.
Anzeige
![]() ![]() ![]() Ein absolutes Muss - Geballtes Wissen aus mehr als 8 Jahren vb@rchiv! - nahezu alle Tipps & Tricks und Workshops mit Beispielprojekten - Symbol-Galerie mit mehr als 3.200 Icons im modernen Look Weitere Infos - 4 Entwickler-Vollversionen (u.a. sevFTP für .NET), Online-Update-Funktion u.v.m. |
Neu! sevCoolbar 3.0 ![]() Professionelle Toolbars im modernen Design! Mit sevCoolbar erstellen Sie in wenigen Minuten ansprechende und moderne Toolbars und passen diese optimal an das Layout Ihrer Anwendung an (inkl. große Symbolbibliothek) - für VB und MS-Access Tipp des Monats TOP Entwickler-Paket ![]() TOP-Preis!! Mit der Developer CD erhalten Sie insgesamt 24 Entwickler- komponenten und Windows-DLLs. Die Einzelkomponenten haben einen Gesamtwert von 1866.50 EUR... |
||||||||||||||||
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein. |