English 中文(简体)
未能将参数价值从时间Span改为时间
原标题:Failed to convert parameter value from a TimeSpan to a DateTime

我正试图从我的文本箱的外地价值中抽出一段时间,但我想到这一例外错误,我究竟是错了吗? 感谢!

Failed to convert parameter value from a TimeSpan to a DateTime.

Passing textbox value:

.CamActiveDateFrom = CDate(uitxtCamDateStart.Text.Trim)

www.un.org/Depts/DGACM/index_spanish.htm 我的变数和财产:

Private _camActiveTimeFrom As Nullable(Of TimeSpan)

Public Property CamActiveTimeFrom() As Nullable(Of TimeSpan)

Get     

Return Me._camActiveTimeFrom        

End Get     

Set(ByVal value As Nullable(Of TimeSpan))            

Me._camActiveTimeFrom = value      

End Set    

End Property

<>12>

 AddInParameter(dbCommand,

    "@ActiveTimeFrom", DbType.Time, 6, DBNull.Value)                

    If (.CamActiveTimeFrom).HasValue Then

     dbCommand.Parameters("@ActiveTimeFrom").Value = .CamActiveTimeFrom     

End If
问题回答

DbType.Time is documented as:

一种显示服务器日值的类型。 如果你想要使用一个服务器的时间价值,则使用<编码>SqlDbType.time。

http://www.un.org/Depts/DGACM/index_chinese.htm

http://msdn.microsoft.com/en-us/library/cc716729.aspx” rel=“noretinger”>,该地图表显示<代码>DbType.time绘图至timeS/pan,因此这里有一些不一致之处,但如果你能够使用一种更具体的类型,那只会是好的。

Of course it s easy to construct a DateTime from a TimeSpan if you want to - you should probably decide on a specific date to always use (e.g. 1st January 2000) so that you can then compare values within the database and effectively get a comparison of just the time bits.

我也存在同样的问题。 而我很抱歉,它只是使用“ToString()”。

my code as following: the date type of "info.START_TIME" is TimeSpan.

db.AddInParameter(dbCommand, "@START_TIME", DbType.Time, info.START_TIME.ToString());

为了使用数据类型时间一栏的“附加”参数,你需要使用SqlDbType而不是DbType(见Joon Skeet的回答)。

db.AddInParameter(dbCommand, "@ActiveTimeFrom", SqlDbType.Time, 6, DBNull.Value)   

而不是

db.AddInParameter(dbCommand, "@ActiveTimeFrom", DbType.Time, 6, DBNull.Value)   

BUT。

页: 1 时间而不是DbType。 时间,你必须宣布数据库标为SqlDatabase,即:

SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();

而不是

Database db = DatabaseFactory.CreateDatabase();

as otherwise it won t take the parameter.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签