2016-06-16 156 views
0

我正在与Visual Studio 2015 Express的C#项目工作,我有一个Access数据库,我想合并到一个项目中,因为我把项目给一个朋友,我必须将Access数据库放到不同的文件夹路径中,所以我想将一个文件夹放入项目中。我不知道文件夹的路径。C#visual studio 2015 Access 2013数据库

+0

对不起,我不完全确定你想要做什么。你想在解决方案中共享访问文件吗?让我们说解决方案的一部分? –

+0

我的连接字符串源我喜欢这个C:\ Users \ user \ Desktop \ es \ file.accdb我想要项目\文件夹\ fileaccdb – George

回答

0

以下为应用程序可执行文件下的.accdb数据库的一个文件夹设置连接。这不适用于ClickOnce安装或使用TableAdapter。

您需要更改数据库到一个真实存在的文件夹,并更改数据库的名称,以匹配您的数据库,

希望这有助于。

// 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 
} 
相关问题