Read data from Access databas



Hi,
I use this code to get data from a Access database and put it in a Listview:

var
l: TListItem;
begin
TAdoQuery.SQL.Text := 'SELECT * FROM Table1;
TAdoQuery.Open;
ListView1.Clear;
ListView1.Items.BeginUpdate;
while Not TAdoQuery.eof do
begin
l := ListView1.Items.Add;
l.Caption := TAdoQuery.Fields.Fields[1].AsString;
l.SubItems.Add(TAdoQuery.Fields.Fields[7].AsString);
TAdoQuery.Next;
end;
ListView1.Items.EndUpdate;

This code works but is there a better way to select fields?
Instead of using field index 1 and 7, I want to use like "Name" and
"Address".

I use Delphi 7.


// Peter


.



Relevant Pages

  • Re: Read data from Access databas
    ... > I use this code to get data from a Access database and put it in a ... > l: TListItem; ...
    (borland.public.delphi.database.ado)
  • Query DB into a ListView - FREEZE
    ... I've got a TADOQuery from which I want to add values to a ListView, ... l: TListItem; ... but there are only 10 fields that match the query conditions. ...
    (borland.public.delphi.database.ado)
  • Re: Syntax error with dates
    ... var MM_abortEdit = false; ... >> I am trying to update an Access database using an ASP form with a ... All I return is a custom error telling me there is a syntax ... > Please reply to the newsgroup. ...
    (microsoft.public.inetserver.asp.db)
  • Re: SQL updates to Access db table taking their time...
    ... Are you using Access database? ... > I have a listview on the screen containing records from a master table. ... (I know I can simply redisplay the actual listview item I was ... > Then if I exit the screen and come back in, voila, there are the changes! ...
    (microsoft.public.vb.database.ado)
  • Re: SpyPrinter "Peter Below"
    ... item: TListitem; ... item.SubItems.Add(IntToStr(jobinfo.BytesPrinted)); ... >> I use SpyPrinter and i want to make a compte total print page for all ...
    (borland.public.delphi.language.objectpascal)