我正在
IErrorInfo.GetDescription因E_FAIL(0x80004005)而失败
我不知道这意味着什么,也不知道如何解决它。当我将acact查询粘贴并粘贴到我的Acces-db并运行它时,它就像一个魅力,但是当我尝试在c#中运行它时,我得到了这个错误。
所有参数都填充了正确的值。
@aankomst = 15-11-2017, @vertrek = 20-11-2017, @grootte = "large"
try
{
standplaatslijst.Clear();
verbinding = new OleDbConnection(
@"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=..\..\..\La_Rustique.accdb;
Persist Security Info=False;");
verbinding.Open();
OleDbCommand query = new OleDbCommand();
OleDbDataReader lezer = null;
query.CommandText = @"SELECT *
FROM standplaats
WHERE id not in (SELECT standplaats_id
FROM reservering
WHERE @aankomst BETWEEN aankomst AND vertrek
AND @vertrek BETWEEN aankomst AND vertrek)
AND size = @grootte";
query.Connection = verbinding;
query.Parameters.Add(new OleDbParameter("@aankomst", OleDbType.DBDate));
query.Parameters["@aankomst"].Value = aankomst;
query.Parameters.Add(new OleDbParameter("@vertrek", OleDbType.DBDate));
query.Parameters["@vertrek"].Value = vertrek;
query.Parameters.Add(new OleDbParameter("@grootte", OleDbType.VarChar));
query.Parameters["@grootte"].Value = grootte;
lezer = query.ExecuteReader();
while (lezer.Read())
{
standplaatslijst.Add(new standplaats(lezer));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
verbinding.Close();
}
我将读者添加到名为standplaats的新类中,如下所示:
public standplaats(OleDbDataReader lezer)
{
_id = lezer.GetInt32(0);
Grootte = lezer.GetString(1);
Name = lezer.GetString(2);
}
答案 0 :(得分:0)
SIZE
是MS Access中的保留字。
将查询更改为:
query.CommandText = @"SELECT *
FROM standplaats
WHERE id not in (SELECT standplaats_id
FROM reservering
WHERE @aankomst BETWEEN aankomst AND vertrek
AND @vertrek BETWEEN aankomst AND vertrek)
AND [size] = @grootte";
Here你找到了保留字的列表。