So I have this code
Im trying to get it so that it retrieves values from the DB between Today and X. The column DateDue is a Long Date column, but no matter what I try and put in the SQL query, I always get "Data Type Mismatch In Criteria Expression".
Any ideas?
Code
string scope = null;
try
{
OleDbCommand tableSearch = connection.CreateCommand();
tableSearch.CommandText = "SELECT * FROM coursework WHERE DateDue BETWEEN '" + System.DateTime.Now.Date.ToString() + "' AND '" + scope+ "'";//sql command
//OleDbParameter todaysDate = new OleDbParameter();
//tableSearch.Parameters.Add(todaysDate);
//OleDbParameter dateDue = new OleDbParameter();
//tableSearch.Parameters.Add(dateDue);//add a parameter
//todaysDate.Value = System.DateTime.Now;
if (whatScope == "week")
{
//dateDue.Value = System.DateTime.Now.AddDays(7).ToLongDateString();//give the parameter a value
}
else if (whatScope == "month")
{
//dateDue.Value = System.DateTime.Now.AddMonths(1).ToLongDateString();
}
else if (whatScope == "today")
{
//dateDue.Value = System.DateTime.Now.ToLongDateString();
scope = System.DateTime.Now.Date.ToString();
}
OleDbDataReader reader = tableSearch.ExecuteReader();
assignmentList.Items.Clear();
while (reader.Read())
assignmentList.Items.Add(reader.GetString(0));
reader.Close();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.ToString());
}Im trying to get it so that it retrieves values from the DB between Today and X. The column DateDue is a Long Date column, but no matter what I try and put in the SQL query, I always get "Data Type Mismatch In Criteria Expression".
Any ideas?






