Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2005, 10:04 AM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copy/import a table from one database to another

What would be the best way to copy/import a table (or tables) from one access database to another? The target database knows nothing of the tables being copied to it. (in VB.Net with ADO.Net)

Thanks.
 
Old March 15th, 2005, 01:04 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

Run script creating tables into The new database then insert data from old database

Ahmed Ali
Software Developer
 
Old March 15th, 2005, 01:10 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you have a quick example?

 
Old May 16th, 2007, 08:21 AM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Copying access table from one database to another database
'-----------------------------------------------------------------------------
Even though this is an old post, i would like to give the solution for this. Because i searched a lot for this and i didnt get a good sample for this. So i think this solution should benefit people who are searching for a similar solution. By making little change this can be used with other databases also.

This is my sample solution.... Try this.

Make two connections of the database from which you want to copy file and another to copy file to.

Sample code......

'--------------------------------------------------------------------------
Public connServer As ADODB.Connection
Public connClient As ADODB.Connection
Public strServerDBPath, strClientDBPath, strServerDB, strClientDB As String

'----------------------------------------------------------------------
strServerDBPath ="C:\Temp\"
strServerDB="Mydata.mdb"
strConnServer= "Driver={Microsoft Access Driver (*.mdb)}; dbq=" & strServerDB & "; DefaultDir=" & strServerDBPath & "; pwd=123456"

strClientDBPath ="C:\Test\"
strClientDB="MyClient.mdb"
strConnClient= "Driver={Microsoft Access Driver (*.mdb)}; dbq=" & strClientDB & "; DefaultDir=" & strClientDBPath & "; pwd=123456"

Set connServer = New ADODB.Connection
connServer.CursorLocation = adUseClient
connServer.Open strConnServer

Set connClient = New ADODB.Connection
connClient.CursorLocation = adUseClient
connClient.Open strConnClient

connClient.Execute "Delete from MyTableName"
' MyTableName is the name of table exists in the destination database
' If it is not exists first create a table through sql.

connServer.Execute "Insert into [" & strClientDBPath & "\" & strClientDB & ";PWD=123456].MyTableName SELECT * From MyTableName"

'--------------------------------------------------------------------------
In this example i used two database, in both the database, same table
should be present.
If not first create the table using sql through "connServer.Execute " and
insert the record. This is not a direct method..... but this will help and
is an easy solution.

Be happy....
sankollam

 
Old May 16th, 2007, 10:46 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

sankollam,

Thank you for providing an answer. However, I'm concerned that you've provided a solution that uses non-.NET technology. Why did you choose to use the old ADODB.Connection object? This is a .NET topic category. Can you provide this solution in .NET?

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
copy table from one access database to another acc fabdulla SQL Language 5 November 21st, 2007 11:13 AM
Copy whole structure of table in #temp table maulik77 SQL Server 2000 2 December 21st, 2006 02:42 AM
copy one table at server1 to another table Jane SQL Server 2000 2 January 31st, 2005 11:11 AM
copy and append records from table-A to table B bhunter Access 6 March 9th, 2004 02:02 PM
Copy a Table VBAHole22 SQL Server 2000 3 June 6th, 2003 10:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.