Solved

Copying a database table "fast" ?...

Posted on 1998-10-04
11
292 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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 …
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 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