FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour DbCombo and RecordSet
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
DbCombo and RecordSet
Posted: Tue Mar 03, 2009 01:54 PM

Hi,

Is it possible to use RecordSet along with DbCombo. ie just like using a DBF with ITEMFIELD and LISTFIELD. My intention is to avoid creating array and just assign a recordset to the DbCombo Control

Regards

Anser

Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM
Re: DbCombo and RecordSet
Posted: Tue Mar 03, 2009 02:50 PM

Hi Anser,
I thing is not possible, we need a new method "FillAdo", to do it. Internally dbCombo allways create array if is not recived via parameter.

Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: DbCombo and RecordSet
Posted: Wed Mar 04, 2009 04:51 AM

Hi Mr.Biel,

Thankyou for the information. I think a METHOD like FillADO() is very much required so that ADO users can utilise this class.
So both DBF and ADO users can utilise DbCombo CLASS effectively. At present we have to read the recordset and create array and pass it to DbCombo

I hope Mr.Antonio will consider this requirement

Regards

Anser

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: DbCombo and RecordSet
Posted: Wed Mar 04, 2009 12:16 PM
A New METHOD to use RecordSet with DbCombo

New Method AdoFill()
Code (fw): Select all Collapse
METHOD AdoFill() CLASS TDBCombo

   // Refill aItems and aList from oRecSet->cFldItem and oRecSet->cFldList

   LOCAL nOldRecNo
   LOCAL nItem, nList,uTest

   IF ::oRecSet == NIL
      // There's no RecordSet defined, so do nothing.
      RETURN NIL
   END IF
   
   ::aItems := {}
   ::aList := {}
  
   TRY
       uTest:=::oRecSet:Fields(::cFldItem):Value
   CATCH
      MsgAlert( "TDBCombo:AdoFill() - FieldName '" + ::cFldItem + "' not found." )
      RETURN NIL   
   END
   
   TRY
      uTest:=::oRecSet:Fields(::cFldList):Value      
   CATCH
      MsgAlert( "TDBCombo:AdoFill() - FieldName '" + ::cFldList + "' not found." )
      RETURN NIL   
   END   

   nOldRecNo := (::oRecSet:Bookmark)
   
   // Don't know why oRecSet:GetRows() not functioning, supposed to Return Array
*   ::aItems := ::oRecSet:GetRows(,,::cFldItem)
*   ::aList  := ::oRecSet:GetRows(,,::cFldList)
   ::oRecSet:MoveFirst()
   DO WHILE !(::oRecSet:Eof())
        AADD( ::aItems, ::oRecSet:Fields(::cFldItem):Value)
        AADD( ::aList, ::oRecSet:Fields(::cFldList):Value)
        ::oRecSet:MoveNext()
   EndDo

   ::oRecSet:Bookmark:=nOldRecNo

RETURN NIL


Sample showing how to use RecordSet with DbCombo

Code (fw): Select all Collapse
// Sql used to create the recordset
cSql:="Select UserName,User_Id from users where Branch_ID= 1"

// oRecSet is the RecordSet Object

@2.3,1 DBCOMBO oDbCmb VAR nUserId ;
      size 120,200 ;      // Size Control width, Ht of the list when activated
      of oDlg;
      ITEMFIELD "User_ID" ;
      LISTFIELD "UserName" ;
      RECORDSET oRecSet ;
      ON CHANGE MsgInfo(nUserId)


Regards

Anser
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: DbCombo and RecordSet
Posted: Wed Mar 04, 2009 01:15 PM

What I think would be a better long-term solution is to create array and recordset classes.

Rather than adding code for DBFs, arrays, and recordsets to all kinds of controls, it makes more sense to me to create array and recordset classes that work just like the TDatabase class. This way the same code in the controls works for all data sources.

The current method of adding code to many controls for each datasource type makes each control more complex and more difficult to modify--each modification needs to account for all datasources.

Another added benefit of datasource classes would be that any code you have written to use a database object could be very simply converted to using an array or recordset object by just changing the datasource object. Simple.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion