Solved

Change columnname runtime

Posted on 1998-06-12
9
403 Views
Last Modified: 2011-10-03
How is it possible to change the name of a column on a Paradox table in Delphi 2 at runtime.
0
Comment
Question by:koger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Expert Comment

by:jhun
ID: 1352511
Why do you want to that ?
John
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1352512
Hi koger,

Do you want to change the column heading for a field in a DB grid?  If so, you can change any of the TFields DisplayLabel properties in your dataset.

JB
0
 
LVL 1

Expert Comment

by:Marcius
ID: 1352513
Hi Koger,

I have done some digging for you on this one, checking SQL etc., but it doesn't look good. The answer is, yes you can change the column name, but it isn't pretty or easy.

Using the BDE, you would have to create a new table containing the new column names. Then copy the data from the old table into the new, then delete the old one. Nasty.

In SQL, you can use

1. ALTER TABLE MyTable ADD MyColumn MyColumnType;
2. UPDATE MyTable
   SET MyColumn = MyOldColumn;

This would allow you to create the new column, but there is no way to use SQL to delete a column. So in this case, you should simply ignore the old column. This will be quicker than using the bde to create and delete tables.

I hope this helps. If you want to simply change the name displayed in the DBGrid, let me know and I will give you more information about that.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:koger
ID: 1352514
To Marcius, I have already done that trick and thought that there have to be a better way, but maybe there isn't
0
 
LVL 1

Expert Comment

by:Marcius
ID: 1352515
I really can't see one, but I will monitor this thread to see if anyone has any better ideas.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1352516
You can do it, but as far as I understood you can't do it with TTable propertys and methods. BDE is capable of doing that, so there must be a way. I'll see what I can find...

Cheers
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1352517
Well, there's an existing PAQ with exactly the same question, but quite a shocking answere. But the answere was accepted so I think it will answere you too.

http://www.experts-exchange.com:80/topics/bin/BuyPAQ?qid=10034159

Also there are links inside to borland TI, but I checked the text there and it didn't work...

Hope this answeres you
bosism@netvision.net.il
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1352518
Any comments?

My seccond answere is to use SQL - I'll tell you the exact command...
0
 
LVL 3

Accepted Solution

by:
Matvey earned 50 total points
ID: 1352519
How about

create a similar table, just with a different field name you want to change
CREATE TABLE <table name>
    (<field name> <field type>
    ..........................
    NewFieldName   OldFieldType,
    ..........................
    <field name> <field type>);

and then copy all the data:
INSERT INTO <table name>
    SELECT * FROM <old table name>

then you just delete the old table and rename the new one to the original name if needed.

It might seem not really like changing a field name - duplicating a table might take a while if it's big, but if your table isn't very big, you won't even notice it.
I've searched all through the non standard SQL commands (that includes ALTER TABLE), and sorrowfully nothing for this task. You can also look at BDE API help for "DbiDoRestructure", that is similar to ALTER TABLE. I didn't find anything else except a replacement for these SQL statements. You can perform the same operation using DbiCreateTable, DbiCopyTable, DbiDeleteTable and DbiRenameTable.       

Hope you find rest at last :)
Regards,
Matvey
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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