Reputation: 3
I’m fetch data from this two dates and date format is custom like this dd/MM/yyyy.. both but not show accurate answer between this two dates
Ther is my code :
private void LoadDataGg()
{
LoadDataGridView.DataSource = Getdatlisttt();
}
private DataTable Getdatlisttt()
{
DataTable dt = new DataTable();
string connstring = ConfigurationManager.ConnectionStrings["AppLogin"].ConnectionString;
string cmdstring = "SELECT FROM ClientRecord WHERE DATE1 >='" + DTpickerfrom.Value.ToString("dd/MM/yyyy") + "'
AND DATE1<='" + DTpickerTo.Value.ToString("dd/MM/yyyy") + "' ";
using (OleDbConnection con11 = new OleDbConnection(connstring))
{
using (OleDbCommand cmd11 = new OleDbCommand(cmdstring, con11))
{
con11.Open();
OleDbDataReader reader = cmd11.ExecuteReader();
dt.Load(reader);
con11.Close();
}
}
return dt;
}
Upvotes: 0
Views: 46
Reputation: 56026
Date values don't hold a format, but as string expression in SQL they must, and you should use the ISO sequence: yyyy-mm-dd. Thus:
string cmdstring = "SELECT FROM ClientRecord WHERE DATE1 >= #" + DTpickerfrom.Value.ToString("yyyy'/'MM'/'dd") + "# AND DATE1 <= #" + DTpickerTo.Value.ToString("yyyy'/'MM'/'dd") + "#";
Upvotes: 1