简体   繁体   中英

C# set desktop path for database

I have created a project in visual studio, that uses a database to store and retrieve details.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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