Rowan Scott
asked on
Create a new mdb (Access Database) from the code in Visual Basic (visual studio express)
Hi.
I am writing a vb application that needs to be able to work from several access databases. The data bases will be essentially the same just different accounts so to speak.
This means I will need to be able to create a new blank database from the code if the user chooses to add another account. How would I do this? I'm a bit new to visual studio so take it slow.
It doesn't have to be an access database. that's just what i'm used to working with.
Best regards
I am writing a vb application that needs to be able to work from several access databases. The data bases will be essentially the same just different accounts so to speak.
This means I will need to be able to create a new blank database from the code if the user chooses to add another account. How would I do this? I'm a bit new to visual studio so take it slow.
It doesn't have to be an access database. that's just what i'm used to working with.
Best regards
Why don't you have a template (empty database) and just make a copy when required?
ASKER
That's a good idea. Do you know how to make a copy with vb code or how to include the template with the installer.
In the installer you can include the database and for copy you just need to do IO.File.Copy(sourceFile,de stFile)
ASKER
Do I make the mdb database manually first using Microsoft Access. Sorry I'm very new to visual studio. I have done lots of vba in excel though so I'm hoping I will pick it up before too long.
>> Do I make the mdb database manually first using Microsoft Access
Yes, it's the easy way! :)
Yes, it's the easy way! :)
ASKER
OK.
I know how to use an mdb from excel's vba but i'm sure there would be a better way in visual studio.
Can you give me any clues.
I know how to use an mdb from excel's vba but i'm sure there would be a better way in visual studio.
Can you give me any clues.
You should use the System.Data.OleDb Namespace
http://msdn.microsoft.com/en-us/library/6d9ew87b(v=VS.71).aspx
You have then several examples:
OleDbConnection
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection(v=VS.71).aspx
OleDbCommand
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand(v=VS.71).aspx
OleDbDataReader
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader(v=VS.71).aspx
OleDbDataAdapter
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter(v=VS.71).aspx
http://msdn.microsoft.com/en-us/library/6d9ew87b(v=VS.71).aspx
You have then several examples:
OleDbConnection
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection(v=VS.71).aspx
OleDbCommand
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand(v=VS.71).aspx
OleDbDataReader
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader(v=VS.71).aspx
OleDbDataAdapter
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter(v=VS.71).aspx
ASKER
I'm not getting this. I've made the mdb database and embedded it.
I cant even work out how to read and write to an embedded text file yet. How do you refer to text files (i will get onto the database later) if they are embedded because you don't know their full address.
Sorry to be so slow!
I cant even work out how to read and write to an embedded text file yet. How do you refer to text files (i will get onto the database later) if they are embedded because you don't know their full address.
Sorry to be so slow!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yippee, thanks jpaulino
Now I can just make copies of the database whenever the user wants to add an account.
I still need to keep a record of what accounts have been added which I thought to do in an "Accounts.txt" file in the resources but your help has solved my original question.
I've used your function so I'm proud to have some resident Portuguese comments in my application now!
Now I can just make copies of the database whenever the user wants to add an account.
I still need to keep a record of what accounts have been added which I thought to do in an "Accounts.txt" file in the resources but your help has solved my original question.
I've used your function so I'm proud to have some resident Portuguese comments in my application now!
ASKER
Thanks very much.
Glad I could help and I think the Portuguese comments will look nice on your application :)
Cheers!
Cheers!