Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Beginner
Mar 21, 1997

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 with any objects on a form. How do I do this?

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

To create a standalone recordset, you first create an object variable to hold the reference to the recordset and then use the NEW DBRECORDSET command to create the recordset. The session that will be used for the recordset is indicated as a parameter of the command.

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

To actually retrieve data, you use the Requery() function, which is NOT in the Power Objects version 1 documentation. The Requery() function causes the SQL statement to be sent to the designated server and 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 the standard recordset methods with it, such as GetColVal() or InsertRow(). It's often easier to use standalone recordsets than to use the EXEC SQL function.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap