2017-06-19 1 views
0

Ich möchte zu wissen, wie es funktioniert zu machen, da es InvalidCastException wirft:Ungültige Span Besetzung in Microsoft.SqlServer.Server

ich versucht habe, mit DateTime.Now.TimeOfDay, aber ich habe den gleichen Fehler.

enter image description here

Stapelüberwachung:

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

Ein SQL Server-Zeitstempel ist mehr eine Versionsnummer als eine tatsächliche Zeit. Es ist ein C# -äquivalenter Datentyp ist "byte []" oder ein Byte-Array. – Cameron

Antwort

1

A SQL Server Timestamp ist kein Zeitstempel per se. Es ist nur eine inkrementierende Zahl, die für die Zeilenversionierung verwendet wird. Das Speichern einer DateTime oder TimeSpan in dieser Spalte ist nicht möglich.

Wenn Sie eine Zeitspanne in der Datenbank speichern möchten, konvertieren Sie sie am besten in ein gängiges Format, z. B. verstrichene Sekunden, und speichern Sie sie als Integer. Weitere Informationen finden Sie unter this article.