无法对System.String和System.DateTime执行'> ='操作 [英] Cannot perform '>=' operation on System.String and System.DateTime

查看:71
本文介绍了无法对System.String和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
Collapse | Copy 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

推荐答案

您始终必须比较相同的对象类型.

您无法比较我们在荷兰所说的苹果和鸡蛋
you allways have to compare the same objecttypes.

You can''t compare apples and eggs we say in Holland


[交易日期]> =#& fnGetClientDate(dtpFromDate.Text)

确保两个字段的类型为DateTime.
[Transaction Date] >= #" & fnGetClientDate(dtpFromDate.Text)

Make sure the type of the two fields is DateTime.


这篇关于无法对System.String和System.DateTime执行'&gt; ='操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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