I'm trying to copy certain Access tables from one database to another in my C# winforms app.
The solution presented here works, but has the flaw that column properties aren't copied. For example, I have an Access table in which one string column has Allow Zero Length set to false. When the table is copied, the structure and data all come across, but Allow Zero Length becomes true. And many similar instances like this for many columns of many tables.
This is the approach I have been using:
SELECT c.*
INTO Contacts
FROM Contacts AS c
IN 'C:\MyDB.mdb'
It works fine, but I only get structure and data, not the column properties.
I am already using this DAO dll for some other things, and would be happy to use it for this if I knew how:
This TransferDatabase() doc looks very promising, but I can't figure out how to get an instance/handle of the magical DoCmd. They never mention how to create that object, it just seems to always exist. I have added the reference to the dll and I have this Using statement as well:
using Microsoft.Office.Interop.Access.Dao;
But I can't find any way to create the DoCmd object, nor find the TransferDatabase() function.
So in summary, what's the best way to copy an Access table from one DB to another, including all structure, data, constraints, properties, indexes, etc, etc...everything...within a c# winforms application? Thanks in advance.