0

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;
}
3
  • Sooo... what exactly is your question? Commented May 6, 2016 at 7:44
  • What is your problem Commented May 6, 2016 at 7:59
  • but it not show accurate answer Commented May 24, 2016 at 16:24

1 Answer 1

1

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") + "#";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.