Solved

Change columnname runtime

Posted on 1998-06-12
9
401 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
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!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert memory stream to PDF file 6 182
Delphi problems to abort a printjob 9 34
shape, triangle, dbctrlgrid 3 33
delphi popmenu non latine charcters 3 35
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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