如何解决datetimekeper条件 [英] how to solver the datetimekeper condition

查看:72
本文介绍了如何解决datetimekeper条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





亲爱的专家我想问一个问题



此查询工作正常。

Hi,

Dear Experts I want to ask a question

This Query is working fine.

string query = "select txtDate,txtCustomerName,txtAddress from EntryTable where txtCustomerName='" + txtCustomerName.Text + "' AND txtDate >= '" + Convert.ToDateTime(dateTimePicker1.Value) + " ' AND txtDate <= '" + Convert.ToDateTime(dateTimePicker2.Value) + "' ";



但是当我没有从datetimepicker中选择任何日期时,我遇到了一些问题(1& 2)意味着相同的日期(如17.9.2013)在datetimepicker1和datetimepicker2中的17.9.2013)它找不到这个日期的任何数据。

如果我在datetimekeper1中选择1 6.9.2013然后显示所有数据。



请告诉我查询条件是什么。


But I have some problem when i am not selecting any date from the datetimepicker (1& 2) means equal date (like 17.9.2013 in datetimepicker1 and 17.9.2013 in datetimepicker2) Its not find any data of this date.
if I am selecting in datetimekeper1 "16.9.2013 " then all the data displayed.

Please tell me what is the condition will be put in the query.

推荐答案

你的日期是为这一天设置的,这是真的,但它包含的内容超过 date ,它还包含时间!因此,使用两者进行比较只会导致那些插入到确切时间点的条目,这些条目可能不会返回任何内容...



如果您想要当天的所有条目,在你的例子中它是17.9.2013,确保转换后的 dateTimePicker1.Value 具有 00的那天的第一次值 :00:00

dateTimePicker2.Value ,转换后,最大时间值 23:59:59.997



在您的查询中使用日期时间设置TIME,

示例:
Your date is all set for this one day, that's true, but it contains more than the date, it also contains the time! so comparing using both will result only in those entries which were inserted in the exact time point which probably returns nothing...

If you want all entries of the day, in your example it is 17.9.2013, make sure the dateTimePicker1.Value after converted, has the day's very first time value of 00:00:00
and the dateTimePicker2.Value, after converted, has the largest time value of 23:59:59.997

before you use the datetime in your query set the TIME,
Example:
// use dt1 instead of the dateTimePicker1.Value (and the same for dt2)
Datetime dt1 = dateTimePicker1.Value.Date.AddHours(0).AddMinutes(0).AddSeconds(0);
Datetime dt2 = dateTimePicker2.Value.Date.AddHours(23).AddMinutes(59).AddSeconds(59);







干杯,

Edo




Cheers,
Edo


这篇关于如何解决datetimekeper条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆