Solved

Changing the table name in access by code?

Posted on 2006-06-23
3
156 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
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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

19 Experts available now in Live!

Get 1:1 Help Now