Exceptions with SqlServer and a datetime column (Pocket PC)

  • Thread starter Thread starter J?rgen Stolz
  • Start date Start date
J

J?rgen Stolz

Hi,
I have problems with a real device filling datetime column´s. If I
test the same with the emulator all works fine.

I create a table
string strSqlCreateTable = "CREATE TABLE T_LOG (" +
"C_LOG_DATE_TIME datetime NOT NULL," +
"C_LOG_INFO_CODE int," +
"C_LOG_INFO_MSG nvarchar(128)," +
"C_LOG_ERROR_CODE int," +
"C_LOG_ERROR_MSG nvarchar(128))";

and I insert data in the following way
DateTime logTime = DateTime.Now;
string insertSqlStatement = string.Format("INSERT INTO T_LOG
(C_LOG_DATE_TIME, C_LOG_INFO_CODE," + "C_LOG_INFO_MSG) " + "VALUES
('{0}',{1},'{2}')", logTime, 1, "Test");

With the real device an exception with the info "error in the datepart
format" is thrown.

If I use the following example
DateTime sendedFromMobile = DateTime.Now;
SqlDateTime sended = new SqlDateTime(sendedFromMobile);
string insertSqlStatement = string.Format("INSERT INTO T_LOG
(C_LOG_DATE_TIME, C_LOG_INFO_CODE," + "C_LOG_INFO_MSG) " + "VALUES
('{0}',{1},'{2}')", sended, 1, "Test");

the same error as above occours. Both examples works fine with the
emulator from the "Compact Framework"

Has anybody a hint for me?

Thanks in advance
Juergen
 
One guess is the date format may be set to different in emulator and device
(e.g British and American). When updating the date try to use the format
YYYY-MM-DD and see.

Best Regards,
Y. Sivaram
 
Thanks for the fast reply. I only added a format description and now it
works on both devices.

string insertSqlStatement = string.Format("INSERT INTO T_LOG
(C_LOG_DATE_TIME, C_LOG_INFO_CODE," + "C_LOG_INFO_MSG) " + "VALUES
('{0}',{1},'{2}')", logTime.ToString("dd.MM.yyyy HH:mm:ss"), nInfoCode,
strInfoMsg);

Regards
Juergen
 
Back
Top