Solved

Change columnname runtime

Posted on 1998-06-12
9
397 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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 wav to mp3 in delphi 9 202
HTML text in the body of an email (delphi code) 12 122
DBGrid or StringGrid ? 6 91
Slow Restore if incremental backups using RDiff.exe 4 21
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

822 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