this is the solution
public string UpdateValid(DateTime startDate, DateTime endDate)
{
OleDbConnection conn = new OleDbConnection("my db path"));
string status = null;
string updateSql = "UPDATE Watchreceipt SET valid = false WHERE Dato BETWEEN @startDate AND @endDate AND DriverIDFK = @DriverIDFK";
conn.Open();
OleDbTransaction sqltrans = conn.BeginTransaction();
OleDbCommand updateCmd = conn.CreateCommand();
updateCmd.CommandText = updateSql;
updateCmd.Parameters.AddWithValue("@startDate", startDate);
updateCmd.Parameters.AddWithValue("@endDate", endDate);
updateCmd.Parameters.AddWithValue("@DriverIDFK", UserMapper.driverNumber);
updateCmd.Transaction = sqltrans;
try
{
updateCmd.ExecuteNonQuery();
sqltrans.Commit();
status = "Ok";
}
catch (OleDbException odbe)
{
sqltrans.Rollback();
System.Windows.Forms.MessageBox.Show("Rolled back\n" + odbe.Message);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Systemfejl\n" + ex.Message);
}
finally
{
conn.Close();
}
return status;
}
I changed the SQL statement and deleted some code inside the try block.
Thanks!!