?
Solved

Copying a database table "fast" ?...

Posted on 1998-10-04
11
Medium Priority
?
296 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
[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
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
Industry Leaders: 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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

770 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