在本机上用模拟器运行程序时发生错误报“路径无效。请检查数据库的目录”。
symbol.sdf在程序的目录下
打开数据库的方法如下:
public void opensql()
{
//SqlCommand cm = new System.Data.SqlClient.SqlCommand();
//SqlConnection cn = new SqlConnection();
SqlCeCommand cm = new SqlCeCommand();
SqlCeConnection cn = new SqlCeConnection();
//cn.ConnectionString = "Data Source=symbol.sdf";
//cn.ConnectionString = "server=JC91109;uid=sa;pwd=sa;database=symbol";
cn.ConnectionString = "data source=symbol.sdf";
cn.Open();
cm.Connection = cn;
}
参考:
string appPath =
Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());
string dbcStr = @"Data Source =" +
appPath.Replace(@"\\",@"\") + @"\symbol.sdf";
http://www.xue5.com/itedu/201001/392213.html
请参考 http://www.cnblogs.com/procoder/archive/2010/03/04/windows-mobile-path.html
string constr = "Data Source=" + @"program files\StudentManage\StudentDB.sdf"; 这样就行,需要在BIN 文件夹同级目录下存放数据库文件。