From version FWH 18.05, it is possible to switch datasource from any type and any type and also reconfigure the columns.
It is possible to switch datasources within DBF, TDatabase, ADO, MariaDB Rowset, Dolphin/TMySql Query and PostGre Query. It is not possible to switch with other datasources like arrays, objects, etc.
Syntax:
- Code: Select all Expand view RUN
oBrw:ResetData( [newDataSource], [aCols] )
// Atlease one parameter should be specified
oBrw:ResetData( nil, aCols ) // Reconfigures columns for the existing datasource
oBrw:ResetData( newData ) // Switches to new datasource with all columns
oBrw:ResetData( newData, aCols ) // switches to new datasource with new column setup.
The following sample demonstrates switching of datasources between DBF, TDatabase, ADO RecordSet and MariaDB RowSet. We can also add TDolphin/TMySql/PostGre query.
- Code: Select all Expand view RUN
- #include "fivewin.ch"
REQUEST DBFCDX
function Main()
local oDlg, oBrw
local oDbf, oAdo, oRecSet, oMaria, oRowSet
SET DELETED ON
// OPEN TABLES
USE CLIENTES NEW ALIAS CLI SHARED VIA "DBFCDX"
oDbf := TDataBase():Open( , "STATES", "DBFCDX", .t. )
oAdo := FW_OpenAdoConnection( "xbrtest.mdb" )
oRecSet := FW_OpenRecordSet( oAdo, "select * from customer" )
oMaria := FW_DemoDB()
oRowSet := oMaria:RowSet( "select * from states" )
// CREATE DIALOG AND BROWSE
DEFINE DIALOG oDlg SIZE 800,500 PIXEL TRUEPIXEL
@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE "CLI" AUTOCOLS ;
CELL LINES NOBORDER FOOTERS FASTEDIT
oBrw:CreateFromCode()
// BUTTONS TO SWAP TABLES
@ 10, 20 BTNBMP PROMPT "DBF" SIZE 90,40 PIXEL OF oDlg FLAT ;
ACTION oBrw:ResetData( "CLI" )
@ 10,120 BTNBMP PROMPT "TDATABASE" SIZE 90,40 PIXEL OF oDlg FLAT ;
ACTION oBrw:ResetData( oDbf, { "Code", "Name" } )
@ 10,220 BTNBMP PROMPT "ADO" SIZE 90,40 PIXEL OF oDlg FLAT ;
ACTION oBrw:ResetData( oRecSet, { "FIRST", "CITY", "STATE", "SALARY" } )
@ 10,320 BTNBMP PROMPT "MARIADB" SIZE 90,40 PIXEL OF oDlg FLAT ;
ACTION oBrw:ResetData( oRowSet )
ACTIVATE DIALOG oDlg CENTERED
// CLOSE TABLES
oRecSet:Close()
oAdo:Close()
oRowSet:Close()
oMaria:Close()
oDbf:Close()
CLOSE CLI
return nil