문제

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?

도움이 되었습니까?

해결책

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"));

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top