Skip to content
Advertisement

How to copy Access table to SQL table in C#?

As title says I’ve used odbcconnection to sqlconnection and for the life of me cant get it to work.. Copied a bunch of code from this site but cant get them both to work.

The program just hangs so maybe I am doing something wrong, but would appreciate maybe a bare bones template that i could just fill in the connection details and bulk copy the table to table..

Advertisement

Answer

Read the data from Access into a DataTable:

Then use SqlBulkCopy to update SQL:

Of course, there is a much easier way to go straight from Access to SQL Server, using VBA, SQL , or other methods.

https://support.office.com/en-us/article/import-or-link-to-data-in-an-sql-server-database-a5a3b4eb-57b9-45a0-b732-77bc6089b84e

https://www.sqlshack.com/six-different-methods-to-copy-tables-between-databases-in-sql-server/

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement