SQL Server 的日期、时间和日期时间偏移量的等效 C# 数据类型是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/655049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are equivalent C# data types for SQL Server's date, time and datetimeoffset?
提问by Paul Suart
What are the most suitable equivalent C# data types for the date datatypes in SQL Server? I'm specifically looking for
SQL Server 中日期数据类型的最合适的等效 C# 数据类型是什么?我专门找
date
time
datetimeoffset
date
time
datetimeoffset
采纳答案by Jay Riggs
Here are the equivalent CLR data types for date
, time
and datetimeoffset
SQL Server data types:
下面是等效的CLR数据类型date
,time
以及datetimeoffset
SQL Server数据类型:
date- DateTime
, Nullable<DateTime>
time- TimeSpan
, Nullable<TimeSpan>
datetimeoffset- DateTimeOffset
, Nullable<DateTimeOffset>
日期- DateTime
,Nullable<DateTime>
时间- TimeSpan
,Nullable<TimeSpan>
日期时间偏移- DateTimeOffset
,Nullable<DateTimeOffset>
Note that you can find a listing of all SQL Server data types and their CLR equivalents here, Mapping CLR Parameter Data
请注意,您可以在此处找到所有 SQL Server 数据类型及其 CLR 等效项的列表,映射 CLR 参数数据
回答by Cerebrus
The new types are supported only if you install .NET Framework 3.5 SP1.
仅当您安装 .NET Framework 3.5 SP1 时才支持新类型。
SqlDbType.Date
SqlDbType.Time
SqlDbType.DateTime2
SqlDbType.DateTimeOffSet
SqlDbType.Date
SqlDbType.Time
SqlDbType.DateTime2
SqlDbType.DateTimeOffSet
For exhaustive information, see Date and Time Data in SQL Server 2008
有关详尽信息,请参阅SQL Server 2008 中的日期和时间数据