I am getting an
IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
And I don't know what this means nor how to solve it. When I copy and paste the exact query into my Access-db and run it it works like a charm but when I try and run it in c# I get this error.
The parameters all do get filled with the right values.
@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();
}
I'm adding the reader to a new class called standplaats which looks like this:
public standplaats(OleDbDataReader lezer)
{
_id = lezer.GetInt32(0);
Grootte = lezer.GetString(1);
Name = lezer.GetString(2);
}
SIZE
is a reserved word in MS Access.
Change the query to this:
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 you find the list of reserved words.