How to DataSet.Fill with default DateTime values ​​for DateTimeKind.Utc?

I have an application that will read data from SQL and send it through WCF to the client application in a similar way:

SqlDataAdapter da = new SqlDataAdapter( cmd )
DataSet ds = new DataSet();
da.Fill( ds );
return ds;

All date / time is stored in the database in UTC format. I noticed that if the clock on the computer on which the application is running is distorted, the date / time received by the clients will be distorted. It seems that if the DateTime type is unspecified, WCF will present it as local time inside and send it as such, so any time difference between the application and the client will result in a date / time shift.

I could, of course, go through the datasets as they are restored and fix the date / time fields, but would anyone think of a better way to populate the dataset, so that each DateTime field will be automatically DateTimeKind.Utc on da.Fill ()?

+5
source share
1 answer

SQL Server 2008, "" SQL datetimeoffset SQL . datetimeoffset - /, , SQL 2008 ADO.NET CLR System.DateTimeOffset , UTC. , . MSDN datetimeoffset .

SQL, ADO.NET , : DataColumn.DateTimeMode, , , (DateTimeMode=DataSetDateTime.UnspecifiedLocal, ), (DateTimeMode=DataSetDateTime.Unspecified). .

MSDN , DateTimeMode=DataSetDateTime.Unspecified DataColumn DataSet. .

( , ), DataTable DateTimeMode=DataSetDateTime.Utc Fill - . UTC.

+15

All Articles