简体   繁体   English

两次查询之间似乎无法正常工作

[英]Between query doesn't seem to work well

This doesn't seem to work well any help 这似乎没有任何帮助

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 one also doesn't seem to work well. 这似乎也不是很好。 it gives me records from different dates, sometimes too i don't get any records while they are records with the date i selected 它为我提供了不同日期的记录,有时我也没有得到任何记录,而它们是我选择的日期的记录

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();

Did your query give u the correct result? 您的查询是否给您正确的结果?

I think Payment_date is a string. 我认为Payment_date是一个字符串。 String comparison doesn't give u correct result. 字符串比较不能给您正确的结果。 It should be DateTime instead. 它应该是DateTime。

The operator greater than or lesser than will compare the values of the paymentDate in string. 大于或小于的运算符将比较string中的paymentDate的值。 So it gives u wierd result. 所以它给你更奇怪的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM