A list of products available on this site
Documentation for XtraMania's xtras
Prices and links to the online store
Xtras, PDFs, samples
Have a question? Ask us!
Contacts
Logo. www.xtramaina.com  
Home Search E-mail
ADOxtra Samples/OpenRecordset

ADOxtra for Macromedia Director

OpenRecordset sample script

See ADOxtra castlib in Downloads section for this handler and other useful Lingo for ADOxtra.

-- Handler creates a new recordset object
-- connects it to the MS Access database dbPath
-- sets access rights to read or read/write depending on bReadWrite parameter
-- executes SQL query and returns resulting recordset object if successful or
-- string with error description otherwise
on OpenRecordset dbPath, sql, bReadWrite
  if voidP(bReadWrite) then bReadWrite=false
  
  if voidP(sql) then return "OpenRecordset: Required parameter is missing: "&sql
  if voidP(dbPath) then return "OpenRecordset: Required parameter is missing: "&dbPath
  
  -- Creating recordset object
  rst=createObject(xtra "ADOxtra",#recordset)
  if not objectP(rst) then return rst
  
  -- Building connection string
  cnnStr="Provider=Microsoft.Jet.OLEDB.4.0;" -- Microsoft Jet provider for MS Access databases
  cnnStr=cnnStr&"Data Source="&dbPath&";"
  if bReadWrite then
    cnnStr=cnnStr&"Mode=Read|Write;"
  else
    cnnStr=cnnStr&"Mode=Read;"
  end if
  
  rst.ActiveConnection=cnnStr
  if rst.failed then return rst.lastError
  
  if bReadWrite then
    rst.lockType=rst.adLockPessimistic
    rst.CursorType=rst.adOpenKeyset
  else
    rst.lockType=rst.adLockReadOnly
    rst.CursorType=rst.adOpenStatic
  end if
  
  rst.Open(sql)
  if rst.failed then return rst.lastError
  
  return rst
end

Site homeSearchContact author © Eugene Shoustrov. www.xtramania.com