0

I want to run a simple SQL from Delphi 2007.

I use AdoQuery. My table has a column id and data type is int (autoincrement).

My question is if I execute

select * from comlist

there is no problem, it runs. But if I define a field on SQL like

select compname from comlist

Delphi complains

ado:Field 'id' not found

The Compname column exist in table.

I have the following fields on my table:

id int
creationdate datetime
compid nvarcahr(50)
complocation nvarchar(50)
serial nvarchar(50) 
compname nvarchar(50)

I have error with this code:

ado.Close;
ado.SQL.Clear;
ado.SQL.Add('SELECT   compname  FROM comlist');
ado.Open;

I have no error with this code:

ado.Close;
ado.SQL.Clear;
ado.SQL.Add('SELECT * FROM comlist');
ado.Open;

What could be the problem?

9
  • Please double check from table definition, the spelling of column(compname) you specifying in select query. Commented Sep 12, 2013 at 9:51
  • Hi but I get this error whatever I write as column. for ex tried with other columns like compid or complocation. but result is same Commented Sep 12, 2013 at 9:55
  • Please, show us the structure of that comlist table! What columns, what datatypes? Commented Sep 12, 2013 at 9:56
  • can you output a sample of results of SELECT * FROM comlist? Commented Sep 12, 2013 at 9:57
  • 1
    Please do not put code samples or sample data into comments - since you cannot format it, it's extremely hard to read it.... Instead: update your question by editing it to provide that additional information! Thank you. Commented Sep 12, 2013 at 10:02

1 Answer 1

5

You might have fields defined in your query component. Select ADOQuery component and open Fields editor from context menu and remove fields.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 My thoughts exactly. (persistent fields defined in design mode)
I dont understand why it happen (Becasue I use all field on field editor for every query ) but your suggestion solved my problem
@HakanSubaşı The error is because the fields in the field editor are the ones your ADOQuery expects to get back from the database. But since you changed your query, those fields are no longer returned by the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.