0
之間有什麼格式的區別:SQL Server CE的時間戳移交
DateTime datetimenow = DateTime.Now.ToLocalTime();
和
long ticks = 634687637580000000;
DateTime createdTimestamp = new DateTime(ticks).ToLocalTime();
這導致SQL Server CE拋出錯誤
在有錯誤日期格式的一部分。 [表達式(如果 已知)=]
我試圖插入兩個時間戳到SQL Server CE數據庫中。當前日期時間和過去的日期時間。當前日期和時間(現在)可以插入到表格中的兩個目標字段中,但是當我使用createdTimestamp
時,會引發上述錯誤。
當我在調試中查看當地人的格式是,正好是兩者相同。
目標字段都是datetime
數據類型。
爲什麼可能會引發此錯誤?
編輯:
我只是發現它似乎隻影響時間戳過去。現在和未來的時間戳工作正常。
編輯:添加SQL插入代碼。
查詢是由我自己的SQL Server CE類動態構建的。
{INSERT timeline (TweetID,Author,TimestampOfTweet,TimestampOfCollected,TweetText) VALUES ('185941815562739713','twitterapi','15/12/2011 13:52:39','01/04/2012 15:58:58','TweetDeck access - Update : This issue has been resolved. http://t.co/2yub0tYL')}
執行代碼:
//Take built statement and apply to command text
cmd.CommandText = buildSqlStatement.ToString();
//execute insert
try
{
cmd.Connection = sqlConn;
sqlConn.Open();
int rows = cmd.ExecuteNonQuery();
string results = Convert.ToString(rows);
return results;
}
catch(Exception ex)
{
return ex.Message;
}
finally
{
sqlConn.Close();
}
你沒有顯示你如何*使用*值。請顯示與SqlCE的交互。如果直接包含該值,請嘗試使用參數化SQL。 – 2012-04-01 14:50:47
以上更新。它使用我自己的SQLCE類。 – Damo 2012-04-01 15:02:19
那麼回到我以前的觀點,你應該使用參數化的SQL語句。然後司機會爲你處理轉換。 – 2012-04-01 15:07:08