Solved

how to get information?

Posted on 2004-10-02
16
181 Views
Last Modified: 2010-04-05
on create i get error: field '`1`' not found

<-- code  -->
procedure TForm3.FormCreate(Sender: TObject);
begin
PComputerName:= StrAlloc(100); Size:= 100;
if GetComputerName(PComputerName, Size) then
pc := PcomputerName;
Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips');
Form1.AdoQuery2.ExecSQL;
Label1.Caption := Form1.Adoquery2.FieldByName('`1`').Value;
Label2.Caption := Form1.Adoquery2.FieldByName('`2.5`').Value;
Label3.Caption := Form1.Adoquery2.FieldByName('`5`').Value;
Label4.Caption := Form1.Adoquery2.FieldByName('`10`').Value;
Label5.Caption := Form1.Adoquery2.FieldByName('`20`').Value;
end;

HOW TO FIX IT?
0
Comment
Question by:selas
  • 5
  • 5
  • 3
  • +2
16 Comments
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12209006
what's usage of this character!!? -- > `
I think it's invalid character for field name
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 12209098
When writing:
  select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips
SQL interprets it as a field names 1, 2.5, 5, 10... These are not names of fields (as i think you didn't meant it and that kind of names are invalid anyway). If you wanted to select numbers, write:
  select 1, 2.5, 5, 10, 20, 50, 100, 500, 1000, `time` from chips
The only field name here is `time`. remember, that when you put something between `...` in SQL it's *always* interpreted as a *name* of field, table etc.
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12209211
i'm really mixed about :( , but when we write :
select `1`, `2.5`, `5`, `10`, `20`, `50`, `100`, `500`, `1000`, `time` from chips

SQL interprets these as parameters , not as field names.
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12209221
>The only field name here is `time`. remember, that when you put something between `...` in SQL it's *always* interpreted as a *name* of field, table etc.

then what's differ when we write :
select time from table
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12209246
aren't you in mistake about ` and ' characters ?
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 12209350
no, i'm not. mind the example:

mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> select `1`;
ERROR 1054: Unknown column '1' in 'field list'
mysql>
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 12209408
I'm agree with you about this, :)

but ERROR 1054 is because of sql interprets `1`, `2.5`, ... as parameters not as field names
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 12210698
Well, that's "Unknown column '1' in 'field list'", so there is no column named '1' to be taken...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:Voodooman
ID: 12211450
Hi

Looking a this you have created a field with the name `1`  not  '1' as some people have interpreted. These are not pseudo fields as some people have interpreted (as they would have had to be defined more clearly (1 as Integer etc..., 1 as DateTime etc...)

If you had used the ' and not the ` it would not compile anyway.....

The use of ` as a character in a fieldname is almost certainly invalid (and anyway is bad practice) all field names should contain only alpha numeric characters and underscores (spaces are allowed but frowned on).

It is also bad practice to use spaces and equally bad practice to use the '.' period (I am surprised that any database would allow this).  This has surely only been allowed in the context of the erroneous ` character.

Amir Azhdari is certainly correct in this.

Change the fieldnames to something sensible without the erroneous ` characters (these are not quotation marks - what are they - I see them every day on my keyboard and have not thought of it!) and without the Erroneous '.' periods.

Change them to (example).

1,2.5 (if you must use numbers)

Or One, TwoPointFive etc

If you must use numbers access them like this

Select [1],[2.5] etc

I would never do this myself unless absolutely forced to do so.


Voodooman
0
 

Author Comment

by:selas
ID: 12211755
1, 2.5, 5, 10, 20, 50, 100, 500, 1000, time - column names

then i exec sql: select `1`, `2.5` from chips

i need to get value of column 1 and 2.5
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12212449

Hi

You cant use the character ` in your SQL

Try this

select [1], [2.5],[5],[10],[20],[50],[100],[500],[1000] from chips


Voodooman
0
 

Author Comment

by:selas
ID: 12213082
if i use:

Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('Select [1],[2.5], [5], [10], [20], max(time) from chips group by ivede');
Form1.AdoQuery2.ExecSQL;

i get error in syntax...
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12213379

Hi

Well I see that your problem over the field not found is cured using the [ ] - so I have answered your question.

You will get a syntax error with the new query.

max(Time) would have to be a field called time which is probably a reserved word and you could't use it anyway - perhaps max([Time]) might work.

However you can't group by a field that is not included in an aggregate of some kind - so you will have an error in the syntax.

As your original problem is solved, I suggest you accept the answer and ask another question related to your new query.

Voodooman
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 500 total points
ID: 12214926
name the columns like this:
SELECT 1 AS A1, 2.5 AS A2, 5 AS A5, 10 AS A10, 20 AS A20 ...

and then use
Label1.Caption := Form1.Adoquery2.FieldByName('A1').AsString;

etc. When writing clear code and SQL, stick to some standart rules. Field names, table names, etc should be identifiers - Upper and Lower case letters and numbers and underscore("_"), starting with letter. They should not use reserved words and the name should be no longer that 27 symbols...
This can save you troubles.
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12215323

Form1.AdoQuery2.SQL.Clear;
Form1.AdoQuery2.SQL.Add('Select ivede,[1],[2.5], [5], [10], [20], max([time]) from chips group by ivede');
Form1.AdoQuery2.ExecSQL;

This should work if you have a column called time and a column called ivede

Voodooman
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 12220546

Well it seems that giving the correct answer dosnt seem to matter anymore...... maybe thats why very few people come here compared to when I first started in 1989.

I don't what to be petty but I think selas is wrong in his acceptance of the answer of Ivanov_G.

I am disgusted is all I can say....

Voodooman

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 185
IExtractImage Delphi 14 197
PDF library for Delphi 2 103
control image tags in a string ? 12 108
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now