Reputation: 11
I have a problem while I want to filter data from datetimepicker. When I want to show all rows that have value of datetimepicker, all records in datagridview hiding. Here is my code:
private void dateTimePickerSearch_ValueChanged(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("select * from tbl_Perdoruesi where Data like '" + dateTimePickerSearch.Value + "%'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
Upvotes: 1
Views: 3887
Reputation: 46
T"select * from tbl_Perdoruesi where Data like"
what is "Data" by the way? is it the date? .................. try this
DateTime startT = new DateTime();
DateTime endT = new DateTime();
startT = dateTimePickerSearch.Value.Date; // Ex: 2014-11-24 12:00:00
endT = dateTimePickerSearch.Value.Date.AddDays(1).AddSeconds(-1); // Ex: 2014-11-24 11:59:59
"Select * From tbl_Perdoruesi WHERE DATA Between '" + startT + "' AND '" + endT + "'"
Upvotes: 2
Reputation: 5330
From the code you shared it seems no data is returned from :
"select * from tbl_Perdoruesi where Data like '" + dateTimePickerSearch.Value + "%'"
thus the DataTable dt
will be empty and no record is shown in your data grid.
Upvotes: 0