I am trying to sort my database data in datagridview
using DateTimePicker
control , the type of date column
in my Event_test
table is datetime2
SqlDataAdapter sda = new SqlDataAdapter("SELECT * from Event_test where date between '"
+dateTimePicker1.Value.ToString()+"' AND'"+dateTimePicker2.Value.ToString()+ "'", con);
DataTable data = new DataTable();
sda.Fill(data);
dataGridView1.DataSource = data;
This solution doesn't work properly , it sorts data wrongly at first time and when i change time pickers this error occurs :
Conversion failed when converting date and/or time from character string
Any help is appreciated.
So how shall I adjust the select statement
to get what I need?
Looks like dateTimePicker1
and dateTimePicker2
are both unchangeable ; they are set to 01/10/2016 and 10/10/2016 and whenever i change dates it shows me results between those dates !!