Cannot perform '>=' operation on System.DateTime and System.String

  • Thread starter Thread starter Ieuan
  • Start date Start date
I

Ieuan

I have noticed this problem coming up in newsgroups before I have a
slightly different variation on it.

I have a dataview (dv) that I am filtering:
e.g.
strFilter = "EndDateTime >= '" + txtEndDateFrom.Text + "')";
dv.RowFilter = strFilter

Now, on my computer and one one of my servers this works fine and the
filter filters as requested.

However, on our production server, I get the message "Cannot perform
'>=' operation on System.DateTime".

I've tried many things including having the filter being
strFilter = "EndDateTime >= " +
Convert.ToDateTime(txtEndDateFrom.Text).ToShortDateString()) + "')";
strFilter = "EndDateTime >= #" + txtEndDateFrom.Text + "#)";
strFilter = "EndDateTime >= #" +
Convert.ToDateTime(txtEndDateFrom.Text) + "#)";
strFilter = "EndDateTime >= '#" +
Convert.ToDateTime(txtEndDateFrom.Text) + "#')";

For the ones above I tend to get String not recognised as valid
datetime.

So, I've got 2 servers that'll happily run this code and the
production one doesn't.

The only obvious difference in these servers is although the
production server has the .Net framework installed (same version as
the other 2), the production server doesn't have Visual Studio .Net
installed on it. I really can't see why this would matter and would
rather take the task of installing VS.Net on the server as a last
thing to try.

So, anyone out there got any suggestions as to why the code runs
differently?

Thanks,

Ieuan Roberts
 
It should work.
In your example you have a right bracket at the end of the statement that
may cause it, but it should cause it on the other two computers as well.
Something causing date problems on computers is the settings on the computer
itself, is it month/day or day/month. Providing a date in the format
yyyy-mm-dd or '30 Sep 2004' in your statement works around this problem
(settings independent).
If none of the above, then sorry, I don't know, as it works for me.
 
Hi,

Does this help you out?

Dim strFilterAs String = "EndDateTime >= #" &
CDate(txtEndDateFrom.Text).ToShortDateString & "#"

Dim dv As New DataView(Me.myDataset.myDatatable, strFilter, "",
DataViewRowState.CurrentRows)

JT
 
Thanks for the reply and suggestions.

I thought I'd write my solution on the board as hopefully it may help
someone in the future.

It seems the problem had something to do with the date format on the
production server - although I could not get to the bottom of exactly
what as the regional settings showed it to be identical to the others.

What I had was a pop up calendar, populating a field with the date -
EndDateTime. This was being written as
myCalendar.SelectedDate.ToString("dd/MM/yyyy").

The code was getting confused by what was month and what was the day
bit.

So I now write it out as myCalendar.SelectedDate.ToString("dd MMMM
yyyy") - e.g. 04 October 2004.

I then use this date and convert as such:
strFilter = "EndDateTime >= " +
Convert.ToDateTime(txtEndDateFrom.Text).ToShortDateString()) + "')";

The server can then convert the date correctly according to its own
settings.
 
Back
Top