Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 15th, 2005, 10:04 AM
Registered User
 
Join Date: Mar 2005
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old March 15th, 2005, 01:04 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cairo, , Egypt.
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
Reply With Quote
  #3 (permalink)  
Old March 15th, 2005, 01:10 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you have a quick example?

Reply With Quote
  #4 (permalink)  
Old May 16th, 2007, 08:21 AM
Registered User
 
Join Date: May 2007
Location: , , .
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

Reply With Quote
  #5 (permalink)  
Old May 16th, 2007, 10:46 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:55 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.