[英]C# visual studio 2015 Access 2013 database
I'm working on a C# project with Visual Studio 2015 Express where I have an Access database that I want incorporate into a project, because, I give the project to a friend, I have to place the Access database into a different folder path, so I want make a folder into project. 我正在使用Visual Studio 2015 Express进行C#项目,其中有一个要合并到项目中的Access数据库,因为我将项目交给朋友,所以我必须将Access数据库放置到其他文件夹路径中,所以我想将一个文件夹放入项目。 I don't know the folder's path.
我不知道文件夹的路径。
The following sets up a connection for a .accdb database one folder below the application executable. 下面为应用程序可执行文件下方一个文件夹的.accdb数据库建立连接。 This will not work with a ClickOnce install or if using TableAdapters.
这不适用于ClickOnce安装或使用TableAdapters的情况。
You need to change Databases to a folder that exists and change the database name to match your database, 您需要将数据库更改为存在的文件夹,并更改数据库名称以匹配您的数据库,
Hope this helps. 希望这可以帮助。
// This translates to: AppFolder\Databases\Database1.accdb
// AppFolder: Location of the executable
// DataBases: an existing folder below AppFolder
var databasePathName = Path.Combine(Application.StartupPath,"Databases", "Database1.accdb");
var Builder = new OleDbConnectionStringBuilder()
{
Provider = "Microsoft.ACE.OLEDB.12.0",
DataSource = databasePathName
};
using (OleDbConnection cn = new OleDbConnection() { ConnectionString = Builder.ConnectionString })
{
cn.Open();
// do work
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.