You should use command parameters (msdn) and decimal
for total
type.
public decimal TotalRepairCost(DateTime startdate, DateTime enddate)
{
decimal total;
OleDbConnection oleConn = new OleDbConnection(connString);
oleConn.Open();
string sql = "SELECT SUM(Cost) FROM Repair WHERE RepairDate BETWEEN @StartDate AND @EndDate";
OleDbCommand cmd = new OleDbCommand(sql, oleConn);
cmd.Parameters.Add("@StartDate", OleDbType.Date);
cmd.Parameters["@StartDate"].Value = startdate;
cmd.Parameters.Add("@EndDate", OleDbType.Date);
cmd.Parameters["@EndDate"].Value = enddate;
total = (decimal)cmd.ExecuteScalar();
oleConn.Close();
return total;
}