我的数据库存在于当前项目文件夹的“Earnest_Indieiduals”
public DataBaseConnection()
{
try
{
_connection = new SqlCeConnection(@"Data Source=D:\Earnest Indieiduals\Earnest_Indieiduals\Earnest_Indieiduals\MyDatabase#1.sdf;Password=xxxxxx;");
}
catch (Exception e) { }
}
它会起作用。但它依赖于路径。我希望路径依赖。
答案 0 :(得分:1)
string path =Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "MyDatabase#1.sdf");
_connection =new SqlCeConnection(string.Format(@"Data Source={0};Password=xxxxxx;",path));