|
|
Open Recordset
Added on 4/8/2001
|
Compatibilities:
Required Xtras:
ADOXtra
|
This item has not yet been rated
|
Handler creates a new recordset object, connects it to the MS Access database file dbPath, sets access rights to read or read/write depending on bReadWrite parameter, executes sql query and returns resulting recordset object if successfull or string with error description otherwise.
-- Coded by Eugene Shoustrov
-- author@adoxtra.com
on OpenRecordset dbPath, sql, bReadWrite
if voidP(bReadWrite) then bReadWrite=false
if voidP(sql) then return "sql param is missed"
if voidP(dbPath) then return "dbPath param is missed"
-- Creating recordset object
rst=CreateObject(xtra "ADOxtra",#recordset)
if not objectP(rst) then return rst
-- Building connection string
-- Microsoft Jet provider for MS Access databases
cnnStr="Provider=Microsoft.Jet.OLEDB.4.0;"
cnnStr=cnnStr&"Data Source="&dbPath&";"
if bReadWrite then
cnnStr=cnnStr&"Mode=Read|Write;"
else
cnnStr=cnnStr&"Mode=Read;"
end if
-- Connecting to the db
rst.ActiveConnection=cnnStr
if rst.failed then return rst.lastError
-- Adjusting cursor and lock type
if bReadWrite then
rst.lockType=rst.adLockPessimistic
rst.CursorType=rst.adOpenKeyset
else
rst.lockType=rst.adLockReadOnly
rst.CursorType=rst.adOpenStatic
end if
-- Opening recordset
rst.Open(sql)
if rst.failed then return rst.lastError
return rst
end
|
|