Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to access a field 2

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi,

I'm new to using ADO components. I have successfully managed to populate a TComboBox with some fields from a database using the following code.
Code:
  Cb_VenueList.Items.Clear;
  ADOTable_Venue.First;
  while not ADOTable_Venue.EOF do
  begin
    Cb_VenueList.Items.Add(ADOTable_Venue.FieldByName('Name').AsString + ', ' +
                           ADOTable_Venue.FieldByName('Town').AsString);
    ADOTable_Venue.Next;
  end;

What I am trying to do now is to add the associated "VenueID" to the combobox item as a TObject by using the AddItem method, as you can see from the following code.
Code:
  Cb_VenueList.Items.Clear;
  ADOTable_Venue.First;
  while not ADOTable_Venue.EOF do
  begin
    Cb_VenueList.AddItem(ADOTable_Venue.FieldByName('Name').AsString + ', ' +
                         ADOTable_Venue.FieldByName('Town').AsString,
                         TObject(ADOTable_Venue.FieldByName('VenueID').AsInteger));
    ADOTable_Venue.Next;
  end;

However, this code does not run. An EDatabaseError appears saying 'ADOTable_Venue: Field 'VenueID' not found'. I have checked and double-checked and my venue table definitely contains a field called "VenueID" of type AutoNumber. In fact it is the primary key for that table.

I've probably made a blindingly obvious error but I can't spot it. So, does anyone know how to resolve this?

Your help would be much appreciated!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Thanks Lou, I found RowsAffected but didn't see RecordCount in the help file! Doh!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top