Microsoft.SqlServer.Server

时间:2017-06-19 20:23:34

标签: c# .net sql-server

我想知道如何使它工作,因为它抛出InvalidCastException:

我尝试使用DateTime.Now.TimeOfDay,但我遇到了同样的错误。

enter image description here

堆栈追踪:

em Microsoft.SqlServer.Server.ValueUtilsSmi.SetTimeSpan(SmiEventSink_Default sink, ITypedSettersV3 setters, Int32 ordinal, SmiMetaData metaData, TimeSpan value, Boolean settersSupportKatmaiDateTime)
   em Microsoft.SqlServer.Server.SqlDataRecord.SetTimeSpan(Int32 ordinal, TimeSpan value)
   em Matematica.UI.Areas.Professor.Controllers.ListasController.ObterTurmas(List`1 agendamentos) na C:\Users\murilo\Source\Repos\moderna-matematica\Matematica.UI\Areas\Professor\Controllers\ListasController.cs:linha 127
   em Matematica.UI.Areas.Professor.Controllers.ListasController.Agendar(AdicionarAgendamento agendamento) na C:\Users\murilo\Source\Repos\moderna-matematica\Matematica.UI\Areas\Professor\Controllers\ListasController.cs:linha 112
   em lambda_method(Closure , ControllerBase , Object[] )
   em System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   em System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   em System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   em System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   em System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   em System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   em System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   em System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   em System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()

1 个答案:

答案 0 :(得分:1)

SQL Server Timestamp本身不是时间戳。它只是一个递增的数字,用于行版本控制。无法在该列中存储DateTimeTimeSpan

如果要在数据库中存储时间跨度,最好的办法是将其转换为通用格式,例如经过的秒数,并将其存储为整数。有关详细信息,请参阅this article