[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Changing the table name in access by code?

Posted on 2006-06-23
3
Medium Priority
?
166 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

867 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