devxlogo

I want to retrieve data from a database that is not associated with any objects

I want to retrieve data from a database that is not associated with any objects

Question:
I want to retrieve data from a database that is not associated withany objects on a form. How do I do this?

Answer:
A recordset is a client-side mechanism for holding retrieved datathat is automatically created for each bound container in a PowerObjects application. Power Objects allow you to dynamically createrecordsets that are not connected with any containers.

To create a standalone recordset, you first create an object variableto hold the reference to the recordset and then use the NEWDBRECORDSET command to create the recordset. The session that willbe used for the recordset is indicated as a parameter of the command.

Once the recordset is created, you can specify the data you want froma database by using the SetQuery() method. The SetQuery() method isassociated the recordset with a database session object with thestandard do reference. The first parameter assigns an SQL statementthat will be used to define the recordset and the second parameter isa boolean that indicates whether the recordset will be updateable.OPO will set up columns in the recordset to correspond to the columnsin the SQL statement.

To actually retrieve data, you use the Requery() function, which isNOT in the Power Objects version 1 documentation. The Requery()function causes the SQL statement to be sent to the designated serverand the return of data, if appropriate.

The complete code sequence for using a standalone recordset is:

       DIM objRecSet As Object       DIM sSQL As String       sSQL = "SELECT EMPNO, ENAME, HIREDATE FROM EMP"       objRecSet = NEW DBRECORDSET(MLDATA)       objRecSet.SetQuery( sSQL, FALSE)       objRecSet.Requery()    

Once you have created a standalone recordset, you can use any of thestandard recordset methods with it, such as GetColVal() orInsertRow(). It’s often easier to use standalone recordsets than touse the EXEC SQL function.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist