Solved

Changing the table name in access by code?

Posted on 2006-06-23
3
155 Views
Last Modified: 2010-04-04
Hello Guys,

I have a system that uses access database, this system is over 1.000 computer and it is impossible to me change the access databases in each computer, so I need to make a exe to update the database, this patch will be in internet do be downloaded. My question is:

How can I change my table name by code ? the database is access.

Thanks
0
Comment
Question by:hidrau
3 Comments
 
LVL 10

Assisted Solution

by:atul_parmar
atul_parmar earned 250 total points
Comment Utility
Hi,

Import the DAO type library (DAO_TLB.PAS), add it to your uses list then paste the following code.

var
  FEngine, FDB : OleVariant;
begin
  FEngine := CoDBEngine.Create;
  FDB := FEngine.OpenDatabase('c:\db1.mdb');
  FDB.TableDefs['Table1'].Name := 'NewName';
  FDB.Close;
  FDB := Unassigned;
  FEngine := Unassigned;
end;
0
 
LVL 11

Accepted Solution

by:
calinutz earned 250 total points
Comment Utility
Or without type libraryes... just do it the natural way... create a new table with the new name with the same field structure and then insert into newtable select * from oldtable... Something like this:

AdoQuery1.Active:=false;
 AdoQuery1.SQL.Clear;
 AdoQuery1.SQL.Add('create table NewTABLE (FirstField varchar(30),SecondField varchar(20), 3rdField int)';//Keep the same structure as in the old table
 AdoQuery1.ExecSQL;

 AdoQuery1.Active:=false;
 AdoQuery1.Sql.Clear;
 AdoQuery1.SQL.Add('insert into NewTABLE Select * from OldTABLE); // copy the contents of old table in the new one
 AdoQuery1.ExecSQL;

 AdoQuery1.Active:=false;
 AdoQuery1.Sql.Clear;
 AdoQuery1.SQL.Text:= 'drop table OldTABLE'; //delete the old table
 AdoQuery1.ExecSQL;


And there you go...
0
 
LVL 1

Author Comment

by:hidrau
Comment Utility
thanks very much
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now