Reputation: 435
How to copy a table from one database to another , I'm developing a windows app using c# in .NET.The copying has to be done by the app. Extract data into an empty table in database 2 from a filled table in database1.I'm using access db , Oledbconnection. I found some answers for sql server though , but not really helping.
Upvotes: 1
Views: 3420
Reputation: 91316
You can refer to the second DB in SQL and execute against a connection to the first mdb/accdb:
Connection
using System.Data.OleDb;
<...>
string ConnString =
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\Docs\first.accdb";
OleDbConnection conn = new OleDbConnection(ConnString);
SQL
INSERT INTO Contacts ( ID, [A Text] ) IN 'z:\docs\New.accdb'
SELECT Contacts.ID, Contacts.[A Text]
FROM Contacts;
Or
INSERT INTO [;DATABASE=Z:\Docs\new.accdb].Contacts ( ID, [A Text] )
SELECT Contacts.ID, Contacts.[A Text]
FROM Contacts;
Or to create a table:
SELECT Contacts.ID, Contacts.[A Text] INTO Contacts IN 'z:\docs\New.accdb'
FROM Contacts;
Upvotes: 2