Accessing Fields From a DAO Recordset

Article ID: 859095
Expand all | Collapse all

TechKnowledge Content

Issue

How to use the DAO COM object from Dexterity sanScript to retrieve values from a DAO recordset?

Resolution

The following sample code uses a DSN to connect to Access database. It then retrieves the two fields/columns for every row and displays them to the screen. The Data Access Objects (DAO) library was marked in the Libraries section in Dexterity. The table is named MyTable and there are two columns of type string in the table; ID and Name. The connection string and information would be different if you are connecting to a different kind of database, however the methods used to access table/column information would be the same.

local DAO.Workspace wrkJetWrkSpc;
local DAO.Database dbConnect;
local DAO.DBEngine dbengine;
local DAO.Recordset RcrdSt;
local text SQLStr;

{ === SQL STRING USED ONCE CONNECT TO DB === }
SQLStr = "select * from myTable";

try { === CREATE AND OPEN CONNECTION === }
dbengine=new DAO.DBEngine();

wrkJetWrkSpc = dbengine.CreateWorkspace("NewODBCWorkspace", "", "", DAO.dbUseODBC);
dbConnect = wrkJetWrkSpc.OpenDatabase("Test", DAO.dbDriverComplete, false, "ODBC;DSN=AccessDB");

RcrdSt = dbConnect.OpenRecordset(SQLStr, DAO.dbOpenDynamic, DAO.dbExecDirect, DAO.dbOptimistic);

RcrdSt.MoveFirst();
while not RcrdSt.EOF do

{can access the field by name or position}
warning str(RcrdSt.Fields[].Item["ID"].Value) + " " + str(RcrdSt.Fields[].Item[1].Value);

RcrdSt.MoveNext();

end while;
else
throw;
end try;

This article was TechKnowledge Document ID: 29828

Properties

Article ID: 859095 - Last Review: October 15, 2011 - Revision: 3.0
Keywords: 
kbmbsmigrate kbretire KB859095
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com