Solved

ADO Display label in DB grid

Posted on 2004-04-12
5
258 Views
Last Modified: 2010-04-05
HI I would like to know how do you change the display label of a field in the grid if your TADOQuery SQL are both declared in the codes instead of using components.
looking at the example below, the genre will display as GENRE, product_type will be display as PRODUCT_TYPE in my grid. How do you change it? do i have to declare the stringfields or tfields? I don't know how to do it. Please help.THANKS!

procedure  TFrameProductBook.BitBtnCategoryLookUPClick(Sender: TObject);
var SQL :string;

begin
 SQL := 'select genre, category_id from category, product_type';
 SQL := SQL + ' where product_type = ''B''';
  SQL := SQL + ' order by :order';
  with FormCategoryLU do
  begin
  QryLU.SQL.text := SQL;

  QryLU.Open;
.
,
,
0
Comment
Question by:AgeOfWars
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10811782
   for i := 0 to DBGrid1.Columns.Count - 1 do
      begin
      if DBGrid1.Columns[i].FieldName = 'genre' then
        DBGrid1.Columns[i].Title.Caption := 'Caption genre;
      .....
      end;
0
 
LVL 17

Expert Comment

by:mokule
ID: 10812910
You can also rewrite

 SQL := 'select genre as caption, category_id from category, product_type';

Choose what is more convenient in a given circumstances.
0
 

Author Comment

by:AgeOfWars
ID: 10812997
Hi mkule,
Thanks for you reply. the first one didn't work for me :(
I know that you can manupulate the sql statement, but i wanna find out how to play with the field settings. the Tstringfileds and the Tfields in the columns of the Query because I would wanna make some of them invisible.

do you know any other way? Thanks

Ian
0
 

Author Comment

by:AgeOfWars
ID: 10813034
Hi Mokule,

I have this error.

SQL := 'select genre, category_id from category, product_type';
 SQL := SQL + ' where product_type = ''B''';
  SQL := SQL + ' order by :order';

I can write 'select genre as CAPTION but it would appear as CAPS.
If I tried 'select genre as ''Genre'' from category' it will return error.

Please help.
Thank you
ian

0
 
LVL 17

Accepted Solution

by:
mokule earned 125 total points
ID: 10813145
It should work.
One apostrophe was missed
What do you mean be don't work.

for i := 0 to DBGrid1.Columns.Count - 1 do
      begin
->>  if DBGrid1.Columns[i].FieldName = 'genre' then
          DBGrid1.Columns[i].Title.Caption := 'Caption genre';
      end;

stop program on this instruction in the loop and look what are Your Filed names
If they are CAPS rewrite as

  if DBGrid1.Columns[i].FieldName = 'GENRE' then
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

18 Experts available now in Live!

Get 1:1 Help Now