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

接続文字列に基づいて、SQLiteデータベースではなくSQLServerExpressデータベースに接続します。

(対応するDataAdapterなどと一緒に)のSqlConnection代わりに使用します。SQLiteConnection

于 2012-09-13T12:58:38.340 に答える
0

このタイプのエラーが発生するたびに、接続文字列にエラーが発生する可能性があるため、web.configファイルをトレースします。上記のコードでは、SqlconnectionであるはずのSqliteconnectionについて言及し、コードに対応する変更を加えています。

于 2012-09-17T10:15:35.127 に答える