This works
string connectionstring = Settings.Default.SandboxConnectionString;
using (OleDbConnection con = new OleDbConnection(connectionstring))
{
OleDbCommand cmd = new OleDbCommand("SELECT * FROM invoice where DateTime between @date1 AND @date2", con);
cmd.Parameters.AddWithValue("@date1", dateTimePicker1.Value);
cmd.Parameters.AddWithValue("@date2", dateTimePicker2.Value);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds, "invoice");
dataGridView1.DataSource = ds.Tables["invoice"];
}
But only if there is actually data on the table that matches the dates I selected.
Things to note:
1. I've used a parameterised query.
2. There is no .ToString() on the dateTimePicker values
3. You should really enumerate the columns you want returned from the table i.e. use
SELECT col1, col2, ..., colN FROM invoice
instead of
SELECT * from invoice
4. You should avoid using reserved words for column names on tables - use
InvoiceDate
rather than
DateTime
for example