Finally, an ADO connection
Posted: Sat Jun 16, 2007 1:34 am
Hi Guys,
Let me pass along some code that now allows me to connect to any data strore (using ADO - ActiveX Data Objects). With help from you folks I discovered PureDishelper v.1.5. After modifying the example and installing their library I was abl to connect to Northwind.mdb (and Access database) found on any Access samples directory. The principle of connecting to SQLServer would be similar. As a help to others wanting to do the same I pass on the code for what its worth.
Let me pass along some code that now allows me to connect to any data strore (using ADO - ActiveX Data Objects). With help from you folks I discovered PureDishelper v.1.5. After modifying the example and installing their library I was abl to connect to Northwind.mdb (and Access database) found on any Access samples directory. The principle of connecting to SQLServer would be similar. As a help to others wanting to do the same I pass on the code for what its worth.
Code: Select all
; This is a program to test the connection to Northwind.mdb database using ADO
; example by Peter Cedeno
;Global DbName.s = "Northwind.mdb" ;assuming that it is in the current directory, else add path
Global DbName.s = "C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb"
XIncludeFile "adoconstants.pbi"
dhToggleExceptions(#True)
Procedure OpenDb()
Protected oCN.l ; Connection-Object
Protected ConnectionString.s
Protected SQL.s ; Syntax for use in query
Protected oRS.l ; RecordSet-Object
; Engine Type=4: <= Access 97 Database (JET 3.5)
; Engine Type=5: >= Access 2000 Database (JET 4.0)
; Standardvalue: Engine Type=5
; Connection string.
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DbName + ";Jet OLEDB:Engine Type=5;"
; Create the required ADO-Connection-Object
oCN = dhCreateObject("ADODB.Connection")
If oCN = 0
MessageRequester("Connection", "Couldn't create ADODB.Connection")
ProcedureReturn
EndIf
; Open the connection.
If Not dhCallMethod(oCN, ".Open(%T)", @ConnectionString)
MessageRequester("Connection","The Connection is made")
SQL = "Select * FROM Customers"
dhGetValue("%o", @oRS, oCN, ".Execute(%T)", @SQL)
Repeat
dhGetValue("%b", @EOF, oRS, ".EOF")
If EOF ; end of file
Break
EndIf
dhGetValue("%T", @szResponse, oRS, ".Fields(%T).Value", @"CustomerID")
If szResponse : Debug "ID: " + PeekS(szResponse) : EndIf
dhFreeString(szResponse) : szResponse = 0
dhGetValue("%T", @szResponse, oRS, ".Fields(%T).Value", @"CompanyName")
If szResponse : Debug "Company: " + PeekS(szResponse) : EndIf
dhFreeString(szResponse) : szResponse = 0
dhCallMethod(oRS, ".MoveNext")
ForEver
Else
MessageRequester("Connection", "Couldn't make a Connection")
EndIf
; Close and remove the recordset and connection.
dhCallMethod(oRS, ".Close")
dhCallMethod(oCN, ".Close")
dhReleaseObject(oRS)
dhReleaseObject(oCN)
EndProcedure
OpenDb()