开发者

Propagate a DateTime column of a DataSet to database

I have a DataSet that has a timestamp (i.e. Datetime.Now ) recording the date and time when a row is added to the DataSet in memory. I will later开发者_JS百科 save (or propagate) all these rows to the SQLCE database where the DataSet's timestamp will be propagate to a DateTime column in the database table.

It works fine and datetime comparison is also ok:

dataView1 = new DataView(
    dt,
    "DataTime >= '6/9/2011 5:00:20 PM'",
    "Data_ID ASC",
    DataViewRowState.CurrentRows); 

The above code works ok, but I worry if the program runs on different computer (i.e. another language of Windows) the Datetime.Now format would have a different format, or if I compare data that is record from a different computer, the different format of the DateTime in the database will causes it to fail. Would this problem happen? Or is there a safer way of doing this?


String datetime = String.Format("{0:G}", ur_datetime_variable);

will give you string in M/d/yyyy h:mm:ss tt format and then convert the datetime string to DateTime

here's a link http://www.csharp-examples.net/string-format-datetime/ and there's everything bout datetime formating.


Should you not use CultureInvariant

DateTimeFormatInfo.InvariantInfo

when parsing dates

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜