Article ID: 195512
Article Last Modified on 12/3/2003
* Reusers.prg - Demonstrate that properties are maintained
* when an existing recordset object is closed and reused.
#DEFINE adUseServer 2
#DEFINE adOpenDynamic 2
#DEFINE adLockOptimistic 3
#DEFINE CR chr(13)
oRecordSet = CreateObject("ADODB.Recordset")
lcSQL = "select * from authors"
* Recordset is server-side, dynamic with
* optimistic locking.
WITH oRecordSet
.CursorLocation = adUseServer
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open(lcSQL, ;
"DRIVER={SQL Server};" + ;
"SERVER=YourServerName;" + ;
"DATABASE=pubs;" + ;
"UID=YourUserID;" + ;
"PWD=YourPassword")
ENDWITH
=MessageBox("Query 1 record count: " + ;
ltrim(str(oRecordSet.RecordCount)) + CR + ;
"Cursor Location:" + ltrim(str(oRecordSet.CursorLocation)) + CR + ;
"Cursor Type: " + ltrim(str(oRecordSet.CursorType)) + CR + ;
"Lock Mode: " + ltrim(str(oRecordSet.LockType)))
* Must use the close method to close before changing the
* command.
oRecordSet.Close
lcSQL = "select * from titleauthor"
* Notice no other properties set.
oRecordSet.Open(lcSQL, ;
"DRIVER={SQL Server};" + ;
"SERVER=YourServerName;" + ;
"DATABASE=pubs;" + ;
"UID=YourUserID;" + ;
"PWD=YourPassword")
* Note that the properties set in the original
* persist in its new incarnation, even though the original was
* closed.
=MessageBox("Query 2 record count: " + ;
ltrim(str(oRecordSet.RecordCount)) + CR + ;
"Cursor Location:" + ltrim(str(oRecordSet.CursorLocation)) + CR + ;
"Cursor Type: " + ltrim(str(oRecordSet.CursorType)) + CR + ;
"Lock Mode: " + ltrim(str(oRecordSet.LockType)))
Additional query words: ADO
Keywords: kbinfo kbsqlprog kbdatabase KB195512