C# Microsoft.SqlServer.Server中的TimeSpan强制转换无效
我想知道如何使它工作,因为它抛出了InvalidCastException: 我已经尝试使用DateTime.Now.TimeOfDay,但我得到了相同的错误 堆栈跟踪:C# Microsoft.SqlServer.Server中的TimeSpan强制转换无效,c#,.net,sql-server,C#,.net,Sql Server,我想知道如何使它工作,因为它抛出了InvalidCastException: 我已经尝试使用DateTime.Now.TimeOfDay,但我得到了相同的错误 堆栈跟踪: em Microsoft.SqlServer.Server.ValueUtilsSmi.SetTimeSpan(SmiEventSink_Default sink, ITypedSettersV3 setters, Int32 ordinal, SmiMetaData metaData, TimeSpan value, Boo
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()
SQL Server本身不是时间戳。它只是一个递增的数字,用于行版本控制。无法在该列中存储日期时间或时间跨度
如果要在数据库中存储timespan,最好将其转换为通用格式,如已用秒数,并将其存储为整数。有关详细信息,请参阅。sql server时间戳更多的是版本号,而不是实际时间。它的C等效数据类型是byte[]或字节数组。