Use the ISO DateTime Format: '2014-03-21T17:47:36'
and insert the date inside the quote '' as a varchar
In c#:
string query = string.Format("SELECT * FROM [{0}] WHERE [{1}] > '{2}'", TABLE_NAME, CREATED_COLUMN, startTime.ToString("s"));
Vra
I have a DateTime
in my c# code, and when I'm trying to pass it to SQL Server CE, it returns a SqlCeExpcetion
, I guess it's because of the format...here's what my query gets alike
SELECT * FROM [Receipt] WHERE [Created] > 3/21/2014 5:47:36 PM
the actual code is
string query = "SELECT * FROM [" + TABLE_NAME + "] WHERE [" + CREATED_COLUMN + "] > " + startTime.ToString();
What format shall I pass to have a normal query?
Oplossing
Use the ISO DateTime Format: '2014-03-21T17:47:36'
and insert the date inside the quote '' as a varchar
In c#:
string query = string.Format("SELECT * FROM [{0}] WHERE [{1}] > '{2}'", TABLE_NAME, CREATED_COLUMN, startTime.ToString("s"));
Ander wenke
Use the ODBC canonical format, or even better use SqlCeParameter with a parameterized Query.
{ts ‘2009-05-11 23:00:00’}
http://erikej.blogspot.dk/2009/06/scripting-sql-datetime-fields-and.html