DateTime.MaxValue overflow error in SQL Server CE

Freshness Warning
This post is more than 3 years old. Please bear in mind its age when reading.

The following lines of code should pass the maximum date  that can be selected to a SQL statement via a parameter.

SqlCeCommand insertCommand = dbConn.CreateCommand();
insertCommand.CommandType = CommandType.Text;
insertCommand.CommandText = "INSERT INTO MyDateTable (DateField) Values (@MyDate)";
insertCommand.Parameters.Add(new SqlCeParameter("MyDate", SqlDbType.DateTime));
insertCommand.Parameters["MyDate"].Value = DateTime.MaxValue
insertCommand.ExecuteNonQuery();


This works fine on all desktop versions of SQL Server, but on SQL Server CE on Windows Mobile returns 'DateTime.MaxValue overflow' A workaround for this (not ideal by any means) can be achieved using:

DateTime.MaxValue.AddMilliseconds(-1);

 

I'm running the 39th BMW Berlin Marathon on 30th September 2012 for the British Lung Foundation, who are currently funding research on the prevention of lung damage in COPD and many other areas related to lung disease.

I'm participating with my sister Claire Kewney and, on behalf of the charity, would appreciate even the smallest donation. My own JustGiving page is here, our team page is here.

if you're in the UK, you can also donate using your mobile phone by texting NKEW82 £5 (or any amount) to 70070. Your donation will be appreciated!

Comments

Your Comment
Your Name
E-mail Address (This won't be published)
Website URL

You can manage your Kewney.com account by logging in. [ Log On ]