开发者

Import Access Database into VB.NET2010 Application and then refer to it locally?

I am writing a program for a class and it needs to read/write to an Access 2007 database. Right now I am referring to it's absolute path when I use it in connection strings, something like:

Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Me\Documents\Visual Studio\Projects\Project1\Database.accdb")

This is going to be a problem when I turn it in obviously, because the professor isn't going to开发者_开发技巧 have the same path. So I want to somehow include it into my project and then refer to it with a relative path or something so that it will work on his machine. When I imported it through the Data Sources it had an option at the end to copy the database into the project which I agreed to. It put the Database where all of the source files are on my computer, so I tried using Application.StartupPath(), but that refers to the folder in bin\Debug when you run the program from Visual Studio (this is not where it put the database). Help!


I feel like this is a bit "hacky" but, if you add it to your solution you can right-click and hit properties. Then make Copy to Output Directory = Copy always to have it always copied to your output directory. Then you can use Application.StartupPath() like you wanted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜