简体   繁体   English

C#为数据库设置桌面路径

[英]C# set desktop path for database

I have created a project in visual studio, that uses a database to store and retrieve details. 我已经在Visual Studio中创建了一个项目,该项目使用数据库来存储和检索详细信息。

I want to deliver an executable and just let the user know that he has to place the database file on the desktop. 我想提供一个可执行文件,只是让用户知道他必须将数据库文件放在桌面上。

if i do 如果我做
String myDesktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

it looks like i cant set the database position after like this: 像这样后,我无法设置数据库位置:

using (SqlCeConnection cn = new SqlCeConnection(@"Data Source = myDesktop\\Database1.sdf))

Any help? 有什么帮助吗?

Form a correct path using the Path.Combine method of the Path class 使用Path类的Path.Combine方法形成正确的路径

string conString = "Data Source=" + Path.Combine(myDesktop, "Database1.sdf;");
using (SqlCeConnection cn = new SqlCeConnection(conString))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM