How do you create a Microsoft Access database file in C# if it does not exist yet?
A developer can work with a Microsoft Access database from Visual C# 2005 or Visual C# . NET by using two separate technologies: Automation and Microsoft ADO.NET. ADO.NET is the preferred technology if you want to work with data objects, such as tables and queries in an Access database.
Access uses Visual Basic for Applications (VBA) as its development language.
The simplest answer is to embed an empty .mdb
/ .accdb
file in your program and write it out to disk.
The correct answer is to use COM Interop with the ADOX library:
var cat = new ADOX.Catalog()
cat.Create(connectionString);
Remember to generate your connection strings using OleDbConnectionStringBuilder
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With