ADO RecordSets - Change SQL & Con at Runtime

ADO RecordSets - Change SQL & Con at Runtime

Postby nageswaragunupudi » Sun Jul 08, 2018 12:26 pm

At times it may be necessary to change the data of a Recordset with totally different data from the same or different tables and even from a different connection. One way is to read the new data into a new recordset and swap with the present recordset.

It is much easier to read the different data into the same recordset in this manner:
Code: Select all  Expand view

oRs:Close()
oRs:Source := cNewSQL
oRs:ActiveConnection := oNewConObject
oRs:Open()
 


If this change is made while the recordset is being browsed, the Browse should be able to handle the change smoothly, which was not possible till FWH18.04.

FWH 18.05 handles the change smoothly, as in this sample:
Code: Select all  Expand view
#include "fivewin.ch"

function Main()

   local oCnMDB, oCnDBF, oCnFWH, oRs
   local cSqlMDB, cSqlDBF, cSqlFWH
   local oDlg, oBrw

   oCnMDB   := FW_OpenAdoConnection( "c:\fwh\samples\xbrtest.mdb" )
   oCnDBF   := FW_OpenAdoConnection( "c:\fwh\samples\" )  
   oCnFWH   := FW_DemoDB( "
ADO" )

   cSqlMDB  := "
SELECT ID,FIRST,CITY,SALARY FROM CUSTOMER"
   cSqlDBF  := "
SELECT * FROM STATES"
   cSqlFWH  := "
SELECT * FROM annual"

   oRs      := FW_OpenRecordSet( oCnMDB, cSqlMDB )

   DEFINE DIALOG oDlg SIZE 700,400 PIXEL TRUEPIXEL

   @ 60, 20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs AUTOCOLS ;
      CELL LINES NOBORDER
   oBrw:CreateFromCode()

   @ 10, 20 BTNBMP PROMPT "
ADO-MDB" SIZE 100,30 PIXEL OF oDlg FLAT ;
      ACTION ReadNewData( oBrw, cSqlMDB, oCnMDB )

   @ 10,140 BTNBMP PROMPT "
ADO-DBF" SIZE 100,30 PIXEL OF oDlg FLAT ;
      ACTION ReadNewData( oBrw, cSqlDBF, oCnDBF )

   @ 10,260 BTNBMP PROMPT "
ADO-MYSQL" SIZE 100,30 PIXEL OF oDlg FLAT ;
      ACTION ReadNewData( oBrw, cSqlFWH, oCnFWH )

   ACTIVATE DIALOG oDlg CENTERED ON INIT oBrw:SetFocus()

   oCnMDB:Close()
   oCnDBF:Close()
   oCnFWH:Close()

return nil

function ReadNewData( oBrw, cSql, oCn )

   WITH OBJECT oBrw:oRs
      :Close()
      :Source           := cSql
      :ActiveConnection := oCn
      CursorWait()
      :Open()
   END
   WITH OBJECT oBrw
      :SetADO( oBrw:oRs, .t. )
      :SetFocus()
   END

return nil


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10313
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ADO RecordSets - Change SQL & Con at Runtime

Postby Antonio Linares » Mon Jul 09, 2018 5:09 am

Very impressive :-)

Great capabilities for the new FWH 18.05 ;-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41411
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests