Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
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
Posted
Updated 7-Feb-12 19:22pm
v3
Comments
Rajesh Anuhya 8-Feb-12 1:10am    
Edited: Code tags added.
--RA

1 solution

Isn't that obvious? The type System.DataTime represent a point on a time scale, a unique point in the global history. The type System.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:

C#
System.DateTime first = System.DateTime.Now;
//do something
System.DateTime second = System.DateTime.Now;
System.TimeSpan interval = second - first; //subtraction operation, naturally


—SA
 
Share this answer
 
v2
Comments
sofia3 8-Feb-12 1:27am    
I think there is no relation in my question and your answer.Please be specific and give me some suggestion reading my whole question one more time.Please suggest me regarding my problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900