0

我不知道为什么在代码中给我这个错误:

无法读取数据库文件

我在 da.fill(dt) 线上收到此错误?

我正在尝试从我的数据库中选择并将它们显示在我的 DayPilotScheduler1 中。

private void loadResources()
{
    DayPilotScheduler1.Resources.Clear();

    string roomFilter = "0";
    if (DayPilotScheduler1.ClientState["filter"] != null)
    {
        roomFilter = (string)DayPilotScheduler1.ClientState["filter"]["room"];
    }
    SQLiteConnection con = new SQLiteConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Korisnik;Integrated Security=True");
    SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT [id], [name], [beds], [bath] FROM [RoomDetails] WHERE beds = @beds or @beds = '0'", con);
    da.SelectCommand.Parameters.AddWithValue("beds", roomFilter);
    DataTable dt = new DataTable();
    da.Fill(dt);

    foreach (DataRow r in dt.Rows)
    {
        string name = (string)r["name"];
        string id = (string)r["id"];
        string bath = (string)r["bath"];
        int beds = Convert.ToInt32(r["beds"]);
        string bedsFormatted = (beds == 1) ? "1 bed" : String.Format("{0} beds", beds);

        Resource res = new Resource(name, id);
        res.Columns.Add(new ResourceColumn(bedsFormatted));
        res.Columns.Add(new ResourceColumn(bath));

        DayPilotScheduler1.Resources.Add(res);
    }
}
4

2 回答 2

3

根据您的连接字符串,您连接的是 SQL Server Express 数据库,而不是 SQLite 数据库。

使用 aSqlConnection代替SQLiteConnection(以及相应的 DataAdapter 等)。

于 2012-09-13T12:58:38.340 回答
0

每当出现这种类型的错误时,连接字符串中就有可能出现错误,因此请跟踪您的 web.config 文件。在上面的代码中,您提到了 Sqliteconnection应该是Sqlconnection,并在代码中进行相应的更改。

于 2012-09-17T10:15:35.127 回答