无法对System.String和System.DateTime执行'> ='操作. [英] Cannot perform '>=' operation on System.String and System.DateTime.
问题描述
我收到以下错误,因为:无法在System.String和System.DateTime上执行> ="操作.当我尝试过滤数据表dtclone以便可以在日期范围内查看报告时.要选择日期,请使用datepicker作为dtpfromdate和dtptodate.当我将系统日期shortdatepattern选择为``M/d/yyyy''时,代码可以正常工作,但是在切换到其他短日期模式时出现错误,错误将在filter.Plz上告诉我,如果im我的问题不清楚.代码如下:
''当用户要显示所选日期范围内的记录时会触发此事件
I am getting the following error as :Cannot perform ''>='' operation on System.String and System.DateTime. When I am trying to filter my datatable dtclone so that i can view the report within the date range.For selecting the dates my using datepicker as dtpfromdate and dtptodate. The code is working when i am selecting the system date shortdatepattern as ''M/d/yyyy'' but it is giving error wen i switch to other short date pattern.error is coming on filter.Plz help me n say me if i m not clear in my question.The code is below:
''This event is fired when user want to display records within the date range selected
Private Sub btnGetReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetReport.Click
Try
btnClearReport.Enabled = True
btnGetReport.Enabled = False
dv = New DataView(dtClone)
Dim strCurCulture As String = System.Threading.Thread.CurrentThread.CurrentCulture.Name
Dim culNew As New System.Globalization.CultureInfo(strCurCulture)
culNew.DateTimeFormat.ShortDatePattern = "M/d/yyyy"
culNew.DateTimeFormat.DateSeparator = "/"
System.Threading.Thread.CurrentThread.CurrentCulture = culNew
System.Threading.Thread.CurrentThread.CurrentUICulture = culNew
Dim filter As String = "[Transaction Date] >= #" & fnGetClientDate(dtpFromDate.Text) & "# and [Transaction Date] <= #" & fnGetClientDate(dtpToDate.Text) & "#"
dv.RowFilter = filter
gvIPDClaimReportView.DataSource = dv
Catch ex As Exception
clsWriteLog.WriteLog("Exception in btnGetReport_Click")
clsWriteLog.WriteLog("Exception : " + ex.Message)
End Try
End Sub
End Sub
''To get the client selected date in ddmmyyyy format
Public Function fnGetClientDate(ByVal ddate As DateTime) As String
Dim dte As DateTime = ddate
''''Added as on 10-10-11 to get proper date for filter
Dim day As String = IIf(Len(dte.Day.ToString()) = 1, "0" & dte.Day.ToString(), dte.Day.ToString())
Dim month As String = CInt(dte.Month)
Dim year As String = dte.Year
'' Dim strCardDate As String = _day + "-" + _month + "-" + _year
'''' Dim strCardDate As String = day + month + year
''''Dim strCardDate As String = _day + "/" + _month + "/" + _year
Dim strCardDate As String = month + "/" + day + "/" + year
Try
Catch ex As Exception
clsWriteLog.WriteLog("Exception in fnGetClientDate")
clsWriteLog.WriteLog("Exception : " + ex.Message)
End Try
Return strCardDate
End Function
在加载时添加此代码
On load am adding this code
Dim strCurCulture As String = System.Threading.Thread.CurrentThread.CurrentCulture.Name
Dim culNew As New System.Globalization.CultureInfo(strCurCulture)
culNew.DateTimeFormat.ShortDatePattern = "M/d/yyyy"
culNew.DateTimeFormat.DateSeparator = "/"
System.Threading.Thread.CurrentThread.CurrentCulture = culNew
System.Threading.Thread.CurrentThread.CurrentUICulture = culNew
Me.StartPosition = FormStartPosition.CenterScreen
'Loads the by default data fovr IPD Claim Report
btnClearReport.Enabled = False
btnGetReport.Enabled = True
dtClone = objMDBLayer.fnGetIPDTransactionReports("")
For i = 0 To dtClone.Rows.Count - 1
Dim strTrDate As String = dtClone.Rows(i)(11).ToString()
Dim format As String = "ddMMyyyy"
'format.DateSeparator = "-"
If (Not strTrDate.Contains("/")) Then
Dim dtTrDate As DateTime = DateTime.ParseExact(strTrDate, format, Nothing)
dtClone.Rows(i)(11) = dtTrDate.ToString("MM/dd/yyyy")
' dtClone.Rows(i)(11) = dtTrDate
End If
Next
gvIPDClaimReportView.DataSource = dtClone
推荐答案
那不是很明显吗?类型System.DataTime
表示时间范围内的一个点,这是全局历史中的唯一点.类型System.TimeSpan
表示事件之间的时间间隔.
更确切地说,相对而言,最好谈论类似时间的间隔.从物理学的角度理解它真的很不错: http://en.wikipedia.org /wiki/Time-like#Time-like_interval [ ^ ].
请参阅:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.timespan.aspx [ ^ ].
除了编程之外,您是否可以将时间间隔与时间间隔(关系不超过")或时间点与另一个时间点(关系不迟于")进行比较,但又不能与另一个时间点进行比较,这不是很明显吗?
重要提示:
Isn''t that obvious? The typeSystem.DataTime
represent a point on a time scale, a unique point in the global history. The typeSystem.TimeSpan
represents a time interval between to events.
More exactly, in relativity it''s better to talk about time-like intervals. It''s good really to understand it from the standpoint of physics: http://en.wikipedia.org/wiki/Time-like#Time-like_interval[^].
Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timespan.aspx[^].
Programming aside, isn''t this obvious that you can compare interval with interval (relationship "not longer than") or time point with another time point (relationship "not later than"), but not one with another?
Important hint though:
System.DateTime first = System.DateTime.Now;
//do something
System.DateTime second = System.DateTime.Now;
System.TimeSpan interval = second - first; //subtraction operation, naturally
这篇关于无法对System.String和System.DateTime执行'> ='操作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!