Solved

Copying a database table "fast" ?...

Posted on 1998-10-04
11
290 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
 
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
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.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now