Unable to open the database file

x624722359 x624722359 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
/// <summary>
/// 获取当前系统程序根目录的路径
/// </summary>
/// <returns></returns>
public static string GetRootPath()
{
string DataPath = "";
if (Environment.OSVersion.Platform.ToString() == "WinCE")
{
DataPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
}
else if (Environment.OSVersion.Platform.ToString() == "Win32NT")
{
DataPath = Directory.GetCurrentDirectory();
}
return DataPath;
}
/// <summary>
/// 连接字符串
/// </summary>
/// <returns></returns>
private SQLiteConnection GetConn()
{
//string connString = "data source=" + Path.GetDirectoryName(Assembly.GetExecutingAssembly ().GetName().CodeBase) + @"\Data\StudentDB.xml";
string connString = "data source=" + GetRootPath() + @"\Data\employeeinfo.xml";
SQLiteConnection conn = new SQLiteConnection(connString);
return conn;
}

这是我的连接数据库代码

下面的conn.Open();是报错的地方
/// <summary>
/// DataTable断开式读取
/// </summary>
/// <param name="sql">传sql语句</param>
/// <returns>返回dataTable对象</returns>
public DataTable ExecDataTable(string sql)
{
SQLiteConnection conn = GetConn();
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}

SQLiteDataAdapter sda = new SQLiteDataAdapter(sql, conn);
DataTable dt = new DataTable();
sda.Fill(dt);
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
return dt;
}


请各位大虾帮我看看问题出在哪里?
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
x624722359
其他数据库 2,208 成员 9,519 内容