Mr. James
This syntax is OK; it is the same as oBrw:setADO( oRS )
Note that a recordset is not an alias. There is no alias used when using a recordset. In TWbrowse you had to set cAlias to nil to prevent it erroring--this was really a workaround for a bug.
The command is same is oBrw:SetAdo( oRs, ...... )
There is no need to say oBrw:cAlias := nil.
The entire problem here is in the variable management.
I provide here a simple sample for switching recordset ( as long as columns are the same )
#include 'fivewin.ch'
#include 'xbrowse.ch'
#define FWPATH "c:\fwh\samples\"
static oCn
function Main()
local cStr := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
FWPATH + ;
";Extended Properties=dBASE III;User ID=Admin;Password=;"
local cSql := 'SELECT FIRST,CITY,STATE FROM CUSTOMER WHERE STATE = "?" ORDER BY FIRST'
local oDlg, oBrw, oRs
local cState := 'NY'
oCn := TOleAuto():New( "ADODB.Connection" )
oCn:Open( cStr )
oCn:CursorLocation := 3 // adUseClient
oRs := TOleAuto():New( "ADODB.RecordSet" )
oRs:Open( StrTran( cSql, '?', cState ), oCn )
DEFINE DIALOG oDlg SIZE 600,400 PIXEL
@ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
AUTOCOLS AUTOSORT RECORDSET oRs ;
CELL LINES NOBORDER
oBrw:CreateFromCode()
@ 10,240 COMBOBOX cState ITEMS { "AK", "AL", "AR", "AZ", "CA", "DA", "GE", "HI", "NY" } ;
SIZE 50,100 PIXEL OF oDlg ;
ON CHANGE ( ;
oBrw:oRs:Close(), ;
oBrw:oRs:Open( StrTran( cSql, "?", cState ), oCn ), ;
oBrw:GoTop(), oBrw:Refresh(), oBrw:SetFocus() )
ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:SetFocus(), .f. )
return nil
Please try this code after changing FWPATH, if necessary.
On selecting a State in the combobox, the recordset is closed and opened with a new Sql and browse is refreshed.