Solved

how to get information?

Posted on 2004-10-02
16
184 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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