2017-06-19 21 views
0

我想知道如何使它的工作,因爲它拋出InvalidCastException的:無效的時間跨度投在Microsoft.SqlServer.Server

我一直在使用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

一個sql服務器時間戳是比實際時間更多的版本號。它的C#等價數據類型是byte []或一個字節數組。 – Cameron

回答

1

一個SQL Server Timestamp不是一個時間戳本身。這只是一個遞增的數字,用於行版本控制。在該列中存儲DateTimeTimeSpan是不可能的。

如果您想在數據庫中存儲時間跨度,最好的方法是將其轉換爲常用格式,例如經過的秒數,並將其存儲爲整數。有關更多信息,請參閱this article