?
Solved

Changing the table name in access by code?

Posted on 2006-06-23
3
Medium Priority
?
163 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
[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
3 Comments
 
LVL 10

Assisted Solution

by:atul_parmar
atul_parmar earned 1000 total points
ID: 16968755
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 1000 total points
ID: 16969392
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
ID: 16971130
thanks very much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 11 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