面临以下问题。我需要在 datagridview 中显示从一个日期到另一个日期的所有付款(如屏幕截图所示)。数据库中有一笔付款,日期为 2020 年 5 月 30 日,仅当两个 dateTimePickers 都包含此日期时,它才会显示在 DGV 中,在所有其他情况下,它仍为空。有人可以解释问题是什么并帮助解决请求以使一切正常吗?
表中的 BillDate 字段是日期类型。
private void btnViewBills_Click(object sender, EventArgs e)
{
DateTime fromDate = DateTime.Parse(dtpFromDate.Text);
DateTime toDate = DateTime.Parse(dtpToDate.Text);
con.Open();
dt = new DataTable();
adapt = new SqlDataAdapter("select * from BillInfo where BillDate between '" + fromDate + "' and '" + toDate + "'", con);
adapt.Fill(dt);
billInfoDataGridView.DataSource = dt;
con.Close();
}

像这样试试