Reinking
17-11-2005, 03:07
Eros,
I thought I'd experiment with the ADO module. I couldn't find much help for internal function calls. I wanted to traverse the recordset of the 'Authors' table in BIBLIO.MDB. Can you show me how to get field data out of the recordset object?
Thanks a lot,
John Reinking
example script below...
USES "ADO"
USES "Console"
dim lpConnection as long
dim lpRecordSet as Long
dim sdbName as String Value "c:\ThinBasic\SampleScripts\ODBC\Biblio.mdb"
'---Connection string
dim stConnection as String Value "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sdbName
dim sQuery as String Value "SELECT * FROM [Authors];"
lpConnection=DB_Open(stConnection)
lpRecordSet =RS_Open(lpConnection, sQuery)
RS_Traverse(lpRecordSet)
RS_Close(lpRecordSet)
DB_Close(lpConnection)
console_Waitkey(5)
stop
Function RS_Open(lpConnection as Long, sQuery as String) as Long
Dim lpRecordSet as Long
lpRecordSet=ADO_CreateObject("ADODB.RecordSet")
ADO_RecordSet_Open(lpRecordset, sQuery, lpConnection, %adOpenKeyset, %adLockOptimistic, %adCmdText)
Function=lpRecordSet
End Function
Function RS_Close(lpRecordSet as Long) as Long
'---Close and release the RecordSet
If lpRecordSet Then
ADO_RecordSet_Close(lpRecordSet)
ADO_Release(lpRecordSet)
End If
End Function
Function DB_Open(strConn as String) as Long
dim lpConn as Long
'---Creates an ADO connection object
lpConn = ADO_CreateObject("ADODB.Connection")
If ISFALSE(lpConn) Then
Console_WriteLine("Connection: " & lpConnection & "Ado result: " & ADO_Result & "")
console_Waitkey
Stop
End If
'---Opens database
ADO_Connection_Open(lpConn, strConn)
If ADO_Result Then
Console_WriteLine( "Connection open error: " & ADO_Result & "")
console_waitkey
STOP
End If
Function=lpConn
End Function
Function DB_Close(lpConnection as Long) As Long
'---Close and release the connection
If lpConnection Then
ADO_Connection_Close(lpConnection)
ADO_Release(lpConnection)
End If
End Function
Function RS_Traverse(lpRecordSet as Long) as Long
dim p1 as long value 0
'----- Fetch the first row
ADO_RecordSet_MoveFirst(lpRecordset)
WHILE isFalse(ADO_RecordSet_EOF(lpRecordset))
'----- Get the field info here??????
'----- Fetch the next row
Ado_RecordSet_MoveNext(lpRecordset)
incr p1
WEND
Console_Write("Found:" & str$(p1) & " records.")
End Function
I thought I'd experiment with the ADO module. I couldn't find much help for internal function calls. I wanted to traverse the recordset of the 'Authors' table in BIBLIO.MDB. Can you show me how to get field data out of the recordset object?
Thanks a lot,
John Reinking
example script below...
USES "ADO"
USES "Console"
dim lpConnection as long
dim lpRecordSet as Long
dim sdbName as String Value "c:\ThinBasic\SampleScripts\ODBC\Biblio.mdb"
'---Connection string
dim stConnection as String Value "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sdbName
dim sQuery as String Value "SELECT * FROM [Authors];"
lpConnection=DB_Open(stConnection)
lpRecordSet =RS_Open(lpConnection, sQuery)
RS_Traverse(lpRecordSet)
RS_Close(lpRecordSet)
DB_Close(lpConnection)
console_Waitkey(5)
stop
Function RS_Open(lpConnection as Long, sQuery as String) as Long
Dim lpRecordSet as Long
lpRecordSet=ADO_CreateObject("ADODB.RecordSet")
ADO_RecordSet_Open(lpRecordset, sQuery, lpConnection, %adOpenKeyset, %adLockOptimistic, %adCmdText)
Function=lpRecordSet
End Function
Function RS_Close(lpRecordSet as Long) as Long
'---Close and release the RecordSet
If lpRecordSet Then
ADO_RecordSet_Close(lpRecordSet)
ADO_Release(lpRecordSet)
End If
End Function
Function DB_Open(strConn as String) as Long
dim lpConn as Long
'---Creates an ADO connection object
lpConn = ADO_CreateObject("ADODB.Connection")
If ISFALSE(lpConn) Then
Console_WriteLine("Connection: " & lpConnection & "Ado result: " & ADO_Result & "")
console_Waitkey
Stop
End If
'---Opens database
ADO_Connection_Open(lpConn, strConn)
If ADO_Result Then
Console_WriteLine( "Connection open error: " & ADO_Result & "")
console_waitkey
STOP
End If
Function=lpConn
End Function
Function DB_Close(lpConnection as Long) As Long
'---Close and release the connection
If lpConnection Then
ADO_Connection_Close(lpConnection)
ADO_Release(lpConnection)
End If
End Function
Function RS_Traverse(lpRecordSet as Long) as Long
dim p1 as long value 0
'----- Fetch the first row
ADO_RecordSet_MoveFirst(lpRecordset)
WHILE isFalse(ADO_RecordSet_EOF(lpRecordset))
'----- Get the field info here??????
'----- Fetch the next row
Ado_RecordSet_MoveNext(lpRecordset)
incr p1
WEND
Console_Write("Found:" & str$(p1) & " records.")
End Function