Solved

add field at run time

Posted on 2000-03-11
15
165 Views
Last Modified: 2010-05-18
Is is possible to add a field to a table at run time? If it is possible, can you give me a sample code? Thanks!
0
Comment
Question by:xiangenhu
[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
  • 4
  • 4
  • 3
  • +3
15 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2607893
You can use SQL to do that in most cases:

procedure TDataForm.CreateTableButtonClick(Sender: TObject);

var
  SQLstmt: String;
begin
  Database1.Connected := True;
  SQLstmt := 'CREATE TABLE NewCusts ' +
    '( ' +
    '  CustNo INTEGER, ' +
    '  Company CHAR(40), ' +
    '  State CHAR(2), ' +
    '  PRIMARY KEY (CustNo) ' +
    ')';
  Database1.Execute(SQLstmt, nil, False, nil);
end;
0
 
LVL 15

Expert Comment

by:simonet
ID: 2608039
FOllowing...
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 2608047
hi eps,

thats not exactly what is asked for

hi xiangenhu,
you can use a sql statement like this

alter table YourTableName add testCol char(10)

just put it in a query and use the execSQL-method

sample (Databasename is properly filled):
query1.Clear;
query1.Sql.Add('alter table YourTableName add testCol char(10)');
try
  query1.ExecSQL;
except
  //there was an error
end;

meikl

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!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2608053
hi alex ;-)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2608087
Epsylon changed the proposed answer to a comment
0
 
LVL 15

Expert Comment

by:simonet
ID: 2608097
Hello, Meikl! Hello, Epsylon! How are you folks?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2608154
Everything's going ok here, thanks. How are you?
0
 
LVL 15

Expert Comment

by:simonet
ID: 2608370
Quite fine, thanks! Just bought Delphi 5 Developers Guide, and there's really a lot to read... lots of thing I gotta catch up with.

Alex
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2609184
hi both,

i'm fine too. have terrible much work at last time.
working on three projects at same time.
Delphi 5 Developers Guide seems to be good.
shall i buy it, too?

well, nice to meet you.

meikl
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2610908
listen
0
 
LVL 3

Expert Comment

by:Stefaan
ID: 2611145
Hi,

This has absulutely nothing to do with the question, but Meikl or Alex, is the Delphi 5 Developers Guide worth buying ?

I have bought the Delphi 5 Enterprise a few months ago, and am really looking for some good books.

Thanks a lot,

Stefaan
0
 

Author Comment

by:xiangenhu
ID: 2612708
Great answer. I have implemented and it works! Thanks a lot!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2613120
hi xiangenhu,

glad to helped you
good luck again.

to stefaan,
i don't have it and i want also to know if this a good book.
btw. how are you?

to alex,
can you tell a bit about the book?

meikl
0
 
LVL 3

Expert Comment

by:Stefaan
ID: 2613687
Meikl,

Well, I'm back from wherever I was ;-)
Had quite a lot of work to do, but now that it is done, I'm back to some Experts-Exhange work again.

By the way, I just ordered the book, so I hope it will be a good one ;-)

Best regards,


Stefaan
0
 
LVL 15

Expert Comment

by:simonet
ID: 2614505
Sure... the book is very good, pretty much worth the money.

I also have Delphi 2 Developer's Guide, and there are many things in common, many similar chapters. But D5 DDG inovates in what Delphi 5: COM, CORBA, MTS-support, Internet development, etc.

Besides, there's a direct channel to the authors, Steve Texeira and Xavier Pacheco, through their own newsgroup.

The only think I believe the book lacks is not covering enough of the OpenTools API. Since many things changed from D4 to D5 regarding the OpenTools API, I believe D5 DDG should cover some of it. After all, Ray Lischner's book, Hidden Paths of Delphi 3, is already getting outta date.

Anyhow, it's a must-have for any serious Delphi developer. I rate it 4 1/2 stars (out of 5 max)

Alex
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

717 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