James Bott wrote:Rao,
Are you suggesting that I test the Access table just to test the SQL syntax?
James
/*
local cStr := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
FWPATH + ;
";Extended Properties=dBASE III;User ID=Admin;Password=;"
*/
local cStr := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
FWPATH + "xbrtest.mdb;User Id=admin;Password=;"
#include 'fivewin.ch'
*--------------
FUNCTION Main()
*--------------
LOCAL oDataLink := TOleAuto():New("Datalinks") ,;
oConn := oDataLink:PromptNew()
LOCAL cString := IF( oConn == NIL, '', oConn:connectionString )
LOCAL oCn, oRs
LOCAL oError
LOCAL cSql := "SELECT * FROM CUSTOMER WHERE STATE ='NY'"
IF Empty( cString )
RETU NIL
ENDIF
MsgInfo( cString, 'Connection String' )
oCn := TOleAuto():New( "ADODB.Connection" )
oCn:Open( cString )
WHILE MsgGet( 'SQL', 'Check Sql', @cSql )
cSql := Alltrim( cSql )
TRY
oRs := TOleAuto():New( "ADODB.RecordSet" )
oRs:Open( cSql, oCn , 1, 3 )
xBrowse( oRs )
oRs:Close()
CATCH oError
xBrowse( oError )
END
cSql += Space( 200 )
END
RETU NIL
James Bott wrote:Rao,
The WHERE clause works fine with the Access database.
James
James Bott wrote:Rao,
The WHERE clause works fine with the Access database.
James
#include 'fivewin.ch'
#include 'xbrowse.ch'
#define BS Chr(92) // BackSlash
#define FWPATH "c:" + BS + "fwh" + BS + "samples" + BS
static oCn
function Main()
local oDlg, oBrw, oRsCust
local cState := 'NY'
oRsCust := GetRecordSet( cState )
// now the local variable oRsCust points to the recordset ( state = NY )
DEFINE DIALOG oDlg SIZE 600,400 PIXEL
@ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
AUTOCOLS AUTOSORT RECORDSET oRsCust ;
CELL LINES NOBORDER
// At this state, both the local variable oRsCust and
// oBrw:oRs point to the same record set.
// Any operations done on oRsCust or oBrw:oRs affect the same recordset object.
// If we write oRsCust:Close(), it closes the recordset that is referred to by oBrw:oRs also.
oBrw:CreateFromCode()
// On Change code here can be writting in many ways as long as we keep in mind
// what variables are pointing to what recrodset
@ 10,240 COMBOBOX cState ITEMS { "AK", "AL", "AR", "AZ", "CA", "DA", "GE", "HI", "NY" } ;
SIZE 50,100 PIXEL OF oDlg ;
ON CHANGE ( ; // Both oRsCust and oBrw:oRs refer to same old recordset.
oRsCust := nil, ; // now oBrw:oRs still refers to the old recordset and oRsCust is dilinked
oRsCust := GetRecordSet( cState ), ; // oRsCust refers to new and oBrw:oRs refers to the old recset
oBrw:oRs:Close(), oBrw:oRs := oRsCust, ; // now again both refer to the same new recordset
oBrw:GoTop(), oBrw:Refresh(), oBrw:SetFocus() )
ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:SetFocus(), .f. )
return nil
static function GetRecordSet( cState )
/*
local cStr := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
FWPATH + ;
";Extended Properties=dBASE III;User ID=Admin;Password=;"
*/
local cStr := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
FWPATH + "xbrtest.mdb;User Id=admin;Password=;"
local cSql := 'SELECT FIRST,CITY,STATE FROM CUSTOMER WHERE STATE = "?" ORDER BY FIRST'
local oRs
if oCn == nil
oCn := TOleAuto():New( "ADODB.Connection" )
oCn:Open( cStr )
oCn:CursorLocation := 3 // adUseClient
endif
oRs := TOleAuto():New( "ADODB.RecordSet" )
oRs:Open( StrTran( cSql, '?', cState ), oCn )
return oRs
I got sidetracked when I saw that you could execute SQL statements agains DBFs. This would be very useful for me, especially for some summary reports.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 49 guests