我正在尝试从数据库中读取数据,并将从日期时间选择器中选择的日期作为查询的值传递。我认为,由于错误的数据类型,我不断收到各种错误消息。
我在这里做错了什么?
请帮忙。
磷
private void buttonRetrieveData_Click(object sender, EventArgs e)
{
openConnection();
//TODO: Add function te retrieve data between dates enteren in datetimepickers
DateTime datumVan = dateTimePickerVan.Value;
DateTime datumTot = dateTimePickerTot.Value;
string query = "select * from my_Table where date between '" + datumVan.ToShortDateString() + "' and '" + datumTot.ToShortDateString() + "' order by date desc";
DataSet dset = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(query, connection);
SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
adapter.Fill(dset, "my_Table");
dataGridView1.DataSource = dset;
dataGridView1.DataMember = "my_table";
adapter.Update(dset, "my_Table");
closeConnection();
}