FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ADO RecordSets - Change SQL & Con at Runtime
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
ADO RecordSets - Change SQL & Con at Runtime
Posted: 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 (fw): Select all Collapse
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 (fw): Select all Collapse
#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


Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ADO RecordSets - Change SQL & Con at Runtime
Posted: Mon Jul 09, 2018 05:09 AM

Very impressive :-)

Great capabilities for the new FWH 18.05 ;-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion