Bindingsource.filter交换了一个月和一天,但我不知道为什么? [英] Bindingsource.filter swapping the month and day around but I don't know why?

查看:73
本文介绍了Bindingsource.filter交换了一个月和一天,但我不知道为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的BindingSource.Filter的代码



  Dim  FilterStartMonth 作为 日期 = DateTimePickerTodaysDateTime.Value。日期 
Dim Filter2MonthsBack 作为 日期 = DateTimePickerTodaysDateTime.Value.AddMonths(-2)。 Date

ClockInTimesBindingSource.Filter = EmployeeID =& ComboBoxOfficeEmployeeFilter.SelectedValue& 和日期< ='& Filter2MonthsBack& '和日期> ='& FilterStartMonth& '





当我一步一步地执行它时,这些值是:



Filter2MonthsBack = 1/2 / 2017 12:00:00 AM



FilterStartMonth = 3/2/2017 12:00:00 AM



这是我想要的,但BindingSource.Filter读取:





ClockInTimesBindingSource.Filter =EmployeeID = 49 and Date< = '02 / 01 / 2017'和日期> = '02 / 03/2017'



我无法理解为什么它会在月中和周围交换?



我们非常感谢任何帮助。



我尝试了什么: < br $> b $ b

  Dim  FilterStartMonth  As  日期 = DateTimePickerTodaysDateTime.Value。日期 .ToString(  d
Dim Filter2MonthsBack As Date = DateTimePickerTodaysDateTime.Value.AddMonths(-2)。 Date .ToString( d

ClockInTimesBindingSource.Filter = EmployeeID =& ComboBoxOfficeEmployeeFilter.SelectedValue& 和日期< ='& Filter2MonthsBack& '和日期> ='& FilterStartMonth& '





  Dim  FilterStartMonth 作为 日期 = DateTimePickerTodaysDateTime.Value。日期 
Dim Filter2MonthsBack 作为 日期 = DateTimePickerTodaysDateTime.Value.AddMonths(-2)。日期

ClockInTimesBindingSource.Filter = EmployeeID =& ComboBoxOfficeEmployeeFilter.SelectedValue& 和日期< ='& Filter2MonthsBack.ToString( d)& '和日期> ='& FilterStartMonth.ToString( d)& '





  Dim  FilterStartMonth 作为 日期 = DateTimePickerTodaysDateTime.Value。日期 .ToString(  d
Dim Filter2MonthsBack As Date = DateTimePickerTodaysDateTime.Value.AddMonths(-2)。 Date .ToString( d

ClockInTimesBindingSource.Filter = EmployeeID =& ComboBoxOfficeEmployeeFilter.SelectedValue& 和日期< ='& Filter2MonthsBack.ToString( d)& '和日期> ='& FilterStartMonth.ToString( d)& '

解决方案

您的系统文化设置通常会破坏 ToString 格式。您可以通过执行以下操作来检查它:

  Dim  culture = Globalization.CultureInfo.CurrentCulture 
Dim CultureName = culture.Name
Dim shortDateFormatString = culture.DateTimeFormat.ShortDatePattern
Dim longDateFormatString = culture.DateTimeFormat.LongDatePattern

如果要强制格式化日期,则可以将格式传递给 ToString 因为它被重载以支持自定义格式:

  Dim  reversedDate = 日期 .Now.ToString(  yy-dd-mm'  3/2/17成为17-2-3  

您可以在这里阅读更多相关信息:自定义日期和时间格式字符串 [ ^ ]


This is the code for my BindingSource.Filter

Dim FilterStartMonth As Date = DateTimePickerTodaysDateTime.Value.Date 
Dim Filter2MonthsBack As Date = DateTimePickerTodaysDateTime.Value.AddMonths(-2).Date 

ClockInTimesBindingSource.Filter = "EmployeeID = " & ComboBoxOfficeEmployeeFilter.SelectedValue & " and Date <= '" & Filter2MonthsBack & "' and Date >= '" & FilterStartMonth & "'"



When i go through it step by step as it runs these are the values:

Filter2MonthsBack = 1/2/2017 12:00:00 AM

FilterStartMonth = 3/2/2017 12:00:00 AM

Which is how i want them, but the BindingSource.Filter reads:


ClockInTimesBindingSource.Filter = "EmployeeID = 49 and Date <= '02/01/2017' and Date >= '02/03/2017'"

I can't work out why it is swapping the month and day around??

Any help would be much appreciated.

What I have tried:

Dim FilterStartMonth As Date = DateTimePickerTodaysDateTime.Value.Date.ToString("d") 
Dim Filter2MonthsBack As Date = DateTimePickerTodaysDateTime.Value.AddMonths(-2).Date.ToString("d") 

ClockInTimesBindingSource.Filter = "EmployeeID = " & ComboBoxOfficeEmployeeFilter.SelectedValue & " and Date <= '" & Filter2MonthsBack & "' and Date >= '" & FilterStartMonth & "'"



Dim FilterStartMonth As Date = DateTimePickerTodaysDateTime.Value.Date 
Dim Filter2MonthsBack As Date = DateTimePickerTodaysDateTime.Value.AddMonths(-2).Date 

ClockInTimesBindingSource.Filter = "EmployeeID = " & ComboBoxOfficeEmployeeFilter.SelectedValue & " and Date <= '" & Filter2MonthsBack.ToString("d") & "' and Date >= '" & FilterStartMonth.ToString("d") & "'"



Dim FilterStartMonth As Date = DateTimePickerTodaysDateTime.Value.Date.ToString("d") 
Dim Filter2MonthsBack As Date = DateTimePickerTodaysDateTime.Value.AddMonths(-2).Date.ToString("d") 

ClockInTimesBindingSource.Filter = "EmployeeID = " & ComboBoxOfficeEmployeeFilter.SelectedValue & " and Date <= '" & Filter2MonthsBack.ToString("d") & "' and Date >= '" & FilterStartMonth.ToString("d") & "'"

解决方案

Your system Culture settings usually deturmines the ToString format. You can check it by doing the following:

Dim culture = Globalization.CultureInfo.CurrentCulture
Dim CultureName = culture.Name
Dim shortDateFormatString = culture.DateTimeFormat.ShortDatePattern
Dim longDateFormatString = culture.DateTimeFormat.LongDatePattern

If you want to force the formatting of dates, then you can pass a formate to ToString as it is overloaded to support custom formatting:

Dim reversedDate = Date.Now.ToString("yy-dd-mm") ' 3/2/17 becomes 17-2-3

You can read more about it here: Custom Date and Time Format Strings[^]


这篇关于Bindingsource.filter交换了一个月和一天,但我不知道为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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