Solved

Copying a database table "fast" ?...

Posted on 1998-10-04
11
294 Views
Last Modified: 2013-12-25
Im using ADO 1.5 to connect to an Access Database.

I have a table with some 20000 records. I want to write a
function that will copy this table into another table, faster
than just enumerating each record and adding it to the
targettable. (Which is very slow in this case :)

There must be some faster way to do this?

ADO have a GetRows() function that will return all data from
a recordset into a variant, fassst. I think i need a PutRows()
that will work the otherway around... heh, well - im not that
lucky...

/Mtoft
0
Comment
Question by:mtoft
11 Comments
 
LVL 1

Expert Comment

by:mdanny
ID: 1496616
Have You thought about using a SQL query to accomplish that?
0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1496617
Use the Execute
I am not Sure on your ADO Connection
In RDO I would do this.

Assume a connection called g_rdo
which is opened to that database

'This line will do it.
g_rdo.execute "Select * into NewTable from OldTable"
'This way is 'Fast as balls'

'you can use a 'Where' clause to select only certain records if you like


0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1496618
Here is something a little more ADO Like..

Dim CopyIt As New ADODB.Command
Set CopyIt.ActiveConnection = gado   'where gado is an ADO Connection
CopyIt.CommandText = "Select * into NewTable from OldTable"
CopyIt.Execute
 
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 3

Expert Comment

by:TheAnswerMan
ID: 1496619
Here is something a little more ADO Like..

Dim CopyIt As New ADODB.Command
Set CopyIt.ActiveConnection = gado   'where gado is an ADO Connection
CopyIt.CommandText = "Select * into NewTable from OldTable"
CopyIt.Execute
 
0
 
LVL 2

Author Comment

by:mtoft
ID: 1496620
The tables are in different databases.
0
 
LVL 2

Expert Comment

by:majed100598
ID: 1496621
THE EASIEST WAY TO DO THIS IS BY USING ACCESS PROGRAMM
- CHOOSE AVERSION OF ACCESS COMPATABLE TO YOUR DATABASE
- OPEN DATABASE
- SELECT THE TABLE YOU WANT AND CHOOSE COPY FROM EDIT MENU
- CHOOSE PASTE FROM EDIT MENU
- SET THE NAME OF THE TABLE YOU WANT
0
 
LVL 2

Author Comment

by:mtoft
ID: 1496622
Thank you for that comment Majed, it was ... a comment...

However, this is a question of how to implement a fast table-copy function from one datasource to another, using visual basic. (This is a visual basic group, yes?)



0
 
LVL 2

Author Comment

by:mtoft
ID: 1496623
Thank you for that comment Majed, it was ... a comment...

However, this is a question of how to implement a fast table-copy function from one datasource to another, using visual basic. (This is a visual basic group, yes?)



0
 
LVL 2

Accepted Solution

by:
shchuka earned 200 total points
ID: 1496624
Why do you need to copy the table?  Can you link the table instead?  The following code does the following:
    * Link a table from another database to this database
    * Copy all the data from the linked table into a new table in this database
    * Remove the link to external table
If you can use link, rather use it and remove unnecessary code in this case.

    Dim db1 As Database
    Dim tbdef As TableDef
   
    Set db1 = OpenDatabase("current.mdb")              'Open current database
    Set tbdef = db1.CreateTableDef("TempTable")       'Create TableDef for the link
    tbdef.Connect = ";DATABASE=external.mdb"       'Set the link source database...
    tbdef.SourceTableName = "Output"                      '... and table
    db1.TableDefs.Append tbdef                                'Add link to current database
'Remove the following two lines if you are fine with a link
    db1.Execute ("SELECT * INTO CopyTable FROM TempTable")   'Copy data
    db1.TableDefs.Delete "TempTable"                       'Remove link
    db1.Close                                                          'Close current database

0
 
LVL 3

Expert Comment

by:TheAnswerMan
ID: 1496625
"Select * into NewTable from OLDDatabase..OldTable"

When going from another Database...
0
 
LVL 2

Author Comment

by:mtoft
ID: 1496626
Ok, i cant do it like this in my case - but i think it answers my question...

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 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