The following code assigns DateTime.MaxValue to a parameter. When trying to run this code against the Northwind databse, it will produce the error, "An overflow occurred while converting to datetime".
SqlCeConnection conn = new SqlCeConnection(connStr);
conn.Open();
SqlCeCommand cmd = new SqlCeCommand("select * from employees where [Hire Date] < @paramDate", conn);
SqlCeParameter paramDate = cmd.CreateParameter();
paramDate.ParameterName = "@paramDate";
paramDate.DbType = DbType.DateTime;
paramDate.Value = DateTime.MaxValue;
cmd.Parameters.Add(paramDate);
SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
DataTable tbl = new DataTable();
da.Fill(tbl);
dataGridView1.DataSource = tbl;
conn.Close();
Note that this fails when using MSSQL Compact Edition (MSSQLCE) under a standard WinForm application and a Pocket PPC platform. The same code against a standard desktop MSSQL version will work fine.
The workaround is simple. Just get away from the MaxValue. Of course, this is a workaround, so it's not perfect, but it certainly works for my needs.
paramDate.Value = DateTime.MaxValue.AddMilliseconds(-1);