这似乎没有任何帮助
this.con.Open();
string selectCommandText = "Select * from paymentrecord where Payment_date >= " + dateTimePicker2.Value.ToString("dd-MM-yyyy") + " and Payment_date <" + dateTimePicker1.Value.ToString("dd-MM-yyyy") + "";
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommandText, this.con);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
this.dataGridView1.DataSource = dataTable;
this.con.Close();
这个似乎也不好用。它给了我不同日期的记录,有时我也没有得到任何记录,而他们是我选择日期的记录
this.con.Open();
string selectCommandText = "Select * from paymentrecord where Payment_date BETWEEN " + dateTimePicker2.Value.ToString("dd-MM-yyyy") +" and "+ dateTimePicker1.Value.ToString("dd-MM-yyyy") + "";
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommandText, this.con);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
this.dataGridView1.DataSource = dataTable;
this.con.Close();
答案 0 :(得分:-3)
您的查询是否给出了正确的结果?
我认为Payment_date是一个字符串。字符串比较不会给出正确的结果。它应该是DateTime。
大于或小于的运算符将比较字符串中paymentDate的值。所以它给你带来了可怕的结果。