As already pointed out, parameterization is elemental key for the query to work properly. This does not only help to prevent SQL injections but also helps with possible conversion issues. For example consider if the localization of the dates is different.
Another problem is the lack of using blocks. They should be used to ensure that the objects like OleDbConnection and OleDbDataAdapter are disposed correctly. Note that you have initialized the data adapter twice
Also it would be easier if both ends of the date range would be included in the condition.
So the code should look something like
DataSet dsa = new DataSet();
DataTable dt = new DataTable();
dsa.Tables.Add(dt);
string sqlQuery =
using OleDbconnection connection = new OleDbConnection(...))
using (OleDbCommand command = new OleDbCommand ()) {
command.Connection = connection;
command.CommandText = @"SELECT [Employee Name],[Column1],[column2],[column3],[Flavours],[Date]
FROM [Total]
WHERE [Employee Name] = @name AND [Date] BETWEEN @start AND @end";
command.Parameter.Add("@name", OleDbType.VarChar, 100).Value = employeedata;
command.Parameter.Add("@start", OleDbType.Date).Value = DateTime.Parse(dateTimePicker1.Text).Date;
command.Parameter.Add("@end", OleDbType.Date).Value = DateTime.Parse(dateTimePicker2.Text).Date;
using (OleDbDataAdapter da = new OleDbDataAdapter(sqlQuery, connection)) {
da.Fill(dt);
}
}
connection.Close();
}
dataGridView1.DataSource = dt;
The code may contain errors, it's just an example.
Other notes:
- In your original code you seem to use value from dateTimePicker1 for both start and end limits in your query. I've used dateTimePicker1 and dateTimePicker2 in the example
- Use meaningful name for the variables and the objects. This makes debugging and maintaining the code much easier. For example instead of dateTimePicker1 use StartDatePicker or something similar
- especially use meaningful names in the database objects. Having column names like Column1 or Column2 makes it really hard to understand the queries and to ensure that correct fields are used properly.