我不知道为什么在代码中给我这个错误:
无法读取数据库文件
我在行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);
}
}
答案 0 :(得分:3)
根据您的连接字符串,您将连接到SQL Server Express数据库,而不是SQLite数据库。
使用SqlConnection
代替SQLiteConnection
(以及相应的DataAdapter等)。
答案 1 :(得分:0)
每当出现这种类型的错误时,就有可能在connectionstring中出现错误,因此请跟踪web.config文件。 在上面的代码中,您提到了 Sqliteconnection ,它应该是 Sqlconnection ,并在代码中进行相应的更改。