Time Equivalent (7) SQL Server 2008 Data Type in .NET

What is equivalent to SQL Server 2008 time(7) data type in .NET? I want to store only hours and minutes in this column, for this, what data type should be used in SQL Server!

+4
source share
3 answers

Got a good article from this link.

I will use the timespan data type in dot net as the equivalent of the time (7) of the SQL server data type for storing hours and minutes.

+3
source

MSDN provides a mapping between SQL data types and CLR data types - and offers TimeSpan and Nullable<TimeSpan> (for nulling columns). Note that how you access the data will determine how you really get the value. DbDataReader , for example, does not have a GetTimeSpan method - but SqlDataReader has such a method . I would expect LINQ to SQL or Entity Framework to do the mapping automatically.

+6
source

As John Skeet said, the SqlDataReader class has a GetTimeSpan method.

 conn = new SqlConnection(blablabla); conn.Open(); string sql = "SELECT * FROM MyTable"; SqlCommand sqlCommand = new SqlCommand(sql, conn); reader = sqlCommand.ExecuteReader(); while (reader.Read()) { MyVeryOwnModel mvom = new MyVeryOwnModel(); mvom.timeStart = reader.GetTimeSpan(reader.GetOrdinal("column_time_start")); mvom.timeEnd = reader.GetTimeSpan(reader.GetOrdinal("column_time_end")); } reader.Close(); 
0
source

All Articles