Here is how I create an Ado recordset on demand ..
Rick Lipkin
- Code: Select all Expand view RUN
Func Main()
Local cFile,aDir,nStart,cDefa,xProvider,xSource
Public xDatabase,xConnect
/-- get timestamp on .exe //
cFILE := GetModuleFileName( GetInstance() )
aDIR := DIRECTORY( cFILE )
// where .exe started from is default directory //
nSTART := RAT( "\", cFILE )
cDEFA := SUBSTR(cFILE,1,nSTART-1)
aDIR := NIL
SET DEFA to ( cDEFA )
xDATABASE := "A" // access
// xDATABASE := "S" // sql server
// xCATALOG := "SERVICE"
// xUSERID := "serviceuser"
xPROVIDER := "Microsoft.Jet.OLEDB.4.0"
xSOURCE := cDEFA+"\Groom.mdb"
xPASSWORD := "password"
IF xDATABASE = "A"
xCONNECT := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet OLEDB:Database Password='+xPASSWORD
ELSE
xCONNECT := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD
ENDIF
REQUEST DBFCDX
rddsetdefault ( "DBFCDX" )
...
...
// open a recordset on demand with sql statement and connection string
oRsUser := TOleAuto():New( "ADODB.Recordset" )
oRsUser:CursorType := 1 // opendkeyset
oRsUser:CursorLocation := 3 // local cache
oRsUser:LockType := 3 // lockoportunistic
cSQL := "SELECT * From [Staff] Order by [Lname]"
TRY
oRsUser:Open(cSQL,xCONNECT )
CATCH oErr
MsgInfo( "Error in Opening Staff table" )
RETURN(.F.)
END TRY
xbrowse( oRsUser )
oRsUser:CLose()
oRsUser := nil