1

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.

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

If the target database has Password , Then what will be changes in the above statements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.