DbCombo and RecordSet

DbCombo and RecordSet

Postby anserkk » Tue Mar 03, 2009 1: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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: DbCombo and RecordSet

Postby Biel EA6DD » Tue Mar 03, 2009 2: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/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca

Re: DbCombo and RecordSet

Postby anserkk » Wed Mar 04, 2009 4: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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: DbCombo and RecordSet

Postby anserkk » Wed Mar 04, 2009 12:16 pm

A New METHOD to use RecordSet with DbCombo

New Method AdoFill()
Code: Select all  Expand view
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: Select all  Expand view
// 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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: DbCombo and RecordSet

Postby James Bott » Wed Mar 04, 2009 1: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 68 guests