我在查询BETWEEN时遇到问题。我试图从两个日期之间的表中选择记录,因此,我使用了以下查询:
SqlDataAdapter sda1 = new SqlDataAdapter(
"select distinct * from BLC where DATE_BLC between '" +
dateTimePicker1.Value.ToString() + "' and'" +
dateTimePicker2.Value.ToString() + "'", conx);
当我输入以下日期时:
从日期05/02/2016至日期15/03/2016
它返回介于(06/02/2016到15/03/2016)日期之间的记录,但不会返回日期为05/02/2016的记录。当我选择日期(从05/02/2016到05/02/2016)时,这里没有记录。有人可以告诉我我在做什么错吗?
尝试只传递Date
价值而不是DateTime
价值
SqlDataAdapter sda1 = new SqlDataAdapter("select distinct * from BLC where DATE_BLC between '" + dateTimePicker1.Value.Date.ToShortDateString() + "' and'" + dateTimePicker2.Value.Date.ToShortDateString() + "'", conx);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句