Creating Access Database using Code
-
Hello, Is there a way to create an entire Access database (I know what tables and the relationships needed between the tables) using VB code? For instance, if a user clicked on a "Create Plan" icon, the following database would be created in the back end: Database: Census Tables: Client Plan Employees Contacts If you know of references you could direct me to in order to learn more about this, it would be greatly appreciated. Thanks so much! Vi
-
Hello, Is there a way to create an entire Access database (I know what tables and the relationships needed between the tables) using VB code? For instance, if a user clicked on a "Create Plan" icon, the following database would be created in the back end: Database: Census Tables: Client Plan Employees Contacts If you know of references you could direct me to in order to learn more about this, it would be greatly appreciated. Thanks so much! Vi
There are ways to do this. Are you using VB6 or .NET?
-
There are ways to do this. Are you using VB6 or .NET?
-
Hi Vi. You know, most beginners start with "Hello World" instead of "Create Access Database from Scratch" :-D One way to accomplish what you're describing is through the ADOX library. Here's a link to MSDN documentation introducing ADOX: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admscadoxfundamentals.asp[^] In a nutshell, the ADOX Catalog object's
Create()
method will let you create the .mdb file. Then you can use a standard ADO.NETOleDbConnection
object to connect to the new database file, and an ADO.NETOleDbCommand
object to execute sql statements against the connection. UsingOleDbCommand
'sExecuteNonQuery()
method will let you issue statements like "Create Table xxx ..." to create your tables. Alternatively, you could use ADOX'sTable
object to accomplish the same task. ADOX is a COM library, not a .NET library, meaning that you have to use Interop techniques to use the ADOX objects in your .NET code. This isn't difficult, and there are many articles available on the subject of COM Interop. This article shows an example of using Visual Studio to make the proper references to the COM ADOX library: http://www.tek-tips.com/gfaqs.cfm/lev2/4/lev3/32/pid/796/fid/3888[^] This article (right here on CodeProject) goes more in depth into the concept of Interop. Its fairly long, but toward the bottom are ADOX examples that are directly relevant to the task you're working on - http://codeproject.com/books/186100558x_16.asp[^] I hope this gives you something you can work with. --mike -
Hi Vi. You know, most beginners start with "Hello World" instead of "Create Access Database from Scratch" :-D One way to accomplish what you're describing is through the ADOX library. Here's a link to MSDN documentation introducing ADOX: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/admscadoxfundamentals.asp[^] In a nutshell, the ADOX Catalog object's
Create()
method will let you create the .mdb file. Then you can use a standard ADO.NETOleDbConnection
object to connect to the new database file, and an ADO.NETOleDbCommand
object to execute sql statements against the connection. UsingOleDbCommand
'sExecuteNonQuery()
method will let you issue statements like "Create Table xxx ..." to create your tables. Alternatively, you could use ADOX'sTable
object to accomplish the same task. ADOX is a COM library, not a .NET library, meaning that you have to use Interop techniques to use the ADOX objects in your .NET code. This isn't difficult, and there are many articles available on the subject of COM Interop. This article shows an example of using Visual Studio to make the proper references to the COM ADOX library: http://www.tek-tips.com/gfaqs.cfm/lev2/4/lev3/32/pid/796/fid/3888[^] This article (right here on CodeProject) goes more in depth into the concept of Interop. Its fairly long, but toward the bottom are ADOX examples that are directly relevant to the task you're working on - http://codeproject.com/books/186100558x_16.asp[^] I hope this gives you something you can work with. --mike