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();
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);
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.