?
Solved

Change columnname runtime

Posted on 1998-06-12
9
Medium Priority
?
406 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
Independent Software Vendors: 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 100 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 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