New features are added to PwrDev regurarly.
New is the use of com objects.
The upcomming .NET database 'com wrapper' is a good example to make late bound calls strong typed by using a com object:
Note code like: dr.Connection
Connection is really an object inside dr.
Evt. see also:
New is the use of com objects.
The upcomming .NET database 'com wrapper' is a good example to make late bound calls strong typed by using a com object:
Code:
[b]Local[/b] T [b]As[/b] [b]String[/b] [b]Local[/b] sSQL [b]As[/b] [b]String[/b] [b]Local[/b] dr [b]As[/b] VD_CLR_CommonDB_IDataReader [b]Local[/b] v [b]As[/b] [b]Variant[/b] [i]' Create a datareader object[/i] dr = [b]Class[/b] "VD_CLR_CommonDB_DataReader" [i]' Enable debugging via OutputDebugString() API, for diagnostic purposes only.[/i] dr.EnableDebug = 1 [i]' Establish a connection.[/i] [b]If[/b] dr.Connection.Open( _ [b]Empty[/b] _ , "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BIBLIO.MDB;Persist Security Info=False" ) [b]Then[/b] [i]' Obtain tablenames[/i] T = dr.GetTableNames() [b]If[/b] [b]Len[/b]( T ) = 0 [b]Then[/b] T = dr.LastException.GetLastErrorMessage [b]VD_Debug_Print[/b] "Tables:" & [b]$CrLf[/b] & T [i]' Prepare query and parameters, parameters how it should be done(!)[/i] sSQL = "SELECT TOP 10 * FROM [Authors] WHERE AU_ID < @ID ORDER BY [Author]" dr.Parameters.Clear() dr.Parameters.Add("ID", 100, [b]Empty[/b] ) [i]' Use the query to create a reader object, success implies at least one record was found.[/i] [b]If[/b] dr.Reader.Open( sSQL ) [b]Then[/b] [i]' Enum fieldnames.[/i] T = "'" & dr.Reader.Fields.Names() & "'" [b]VD_Debug_Print[/b] "Fields: " & [b]$CrLf[/b] & T [i]' Enum records, this is a forward-only recordset.[/i] [i]' If the read() returns false, the end of the recordset is reached.[/i] [b]Do[/b] [i]' Obtain data via a variant and/or wrapper methods to obtain nr's and strings as string.[/i] dr.Reader.GetFieldData( 0, v ) [b]VD_Debug_Print[/b] [b]Format$[/b]( [b]Variant#[/b]( v ), "0000" ) & ", " & dr.Reader.GetFieldStr( 1 ) [b]Loop[/b] [b]Until[/b] dr.Reader.Read() = 0 [b]VD_Debug_Print[/b] dr.LastException.GetLastErrorMessage dr.Reader.Close() [b]End[/b] [b]If[/b] [b]Else[/b] T = dr.LastException.GetLastErrorMessage [b]MsgBox[/b] T [b]End[/b] [b]If[/b] [i]' Closing each object in the DataReader class is usually pointless, terminating the DataReader will also close all objects.[/i] dr.Connection.Close() dr = [b]Nothing[/b]
Connection is really an object inside dr.
Evt. see also:
Comment