我从这两个日期获取数据,日期格式是自定义的,如dd / MM / yyyy ..两者都没有显示这两个日期之间的准确答案
Ther是我的代码:
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;
}
答案 0 :(得分:1)
日期值不包含格式,但作为SQL中的字符串表达式,它们必须使用ISO序列:yyyy-mm-dd。因此:
string cmdstring = "SELECT FROM ClientRecord WHERE DATE1 >= #" + DTpickerfrom.Value.ToString("yyyy'/'MM'/'dd") + "# AND DATE1 <= #" + DTpickerTo.Value.ToString("yyyy'/'MM'/'dd") + "#";