Re: Populating a combo from a database table faster




<tglunz@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:442aef09$1@xxxxxxxxxxxxxxxxxxxxxxxxx
Good afternoon,

I was wondering if anyone know a faster way to populate a combo? In some
cases these combos maybe populated from a query which may return 20,000
records. I am not a fan of populating a combo with that many records, but
it is not my choice. The following code take 7 second to populate the
combo
with 20,000 values:

Combo.items.clear;
CodeQuery.First; // ADO dataset
while CodeQuery.Eof = False do
begin
Combo.Items.Add(CodeQuery.Fields[0].AsString);
CodeQuery.Next;
end;


Hi

Try this

//----------------------------------------------------------------------
var
o : Variant;
i : Integer;
c : integer;
begin

Combo.items.clear;
CodeQuery.First; // ADO dataset
//Add ADOInt to get the defines
o := CodeQuery.Recordset.GetRows(adGetRowsRest, adBookmarkCurrent,
'UniqueID' );
c := VarArrayHighBound(o,2);
for i := 0 to c do
begin
Combo.Items.Add(VarArrayGet(o,[0,i]));
end;

ShowMessage(IntToStr(combo.Items.Count ));
end;
//------------------------------------------------------------------------------------------
In my tests it took sub 2 seconds to load 12,000+ items compared to about
6seconds with your code.
Please forgive the poor Delphi style, I use BCB normally.

Hope it helps

Chris


.



Relevant Pages

  • Passing 2 parameters to stored query?
    ... query from a form. ... populate the variables then open the query it ... Set rst = New ADODB.Recordset ... Do Until CalcDate = Me.txtDateTo ...
    (microsoft.public.data.ado)
  • RE: Data entry property & lookup
    ... Dave Hargis, Microsoft Access MVP ... most recently entere record. ... the most recently entered or you can add a date/time stamp field and populate ... I had put an unbound combo box in but didn't set the query up ...
    (microsoft.public.access.forms)
  • Re: Hard to explain - multiple update fields query...
    ... "John Spencer" wrote: ... query to get the data back into the AwardsTable ... AwardsTable in your Access database and do all the work there. ... You will need 40 queries to populate the table from your current table. ...
    (microsoft.public.access.queries)
  • Re: create and/or insert into a table, specifying columns once
    ... >have to create a query that comes up with all of the columns in two places: ... >first to create a new table and then to populate an existing table. ... for all iterations. ... I see no reason to prefer the third or fourth option over this. ...
    (microsoft.public.sqlserver.programming)
  • Passing a value from one form to another
    ... 10 labels and a control array of say 10 buttons. ... This part of it works fine, please do not see this as a DB query. ... hide my 1st form and populate the control array of labels on this 2nd ... from the ID that is stored in the relevant button's tag. ...
    (microsoft.public.vb.enterprise)