如何找到数据库表中两个时间字段之间的差异 [英] How to find the difference between two time fields in a database table

查看:94
本文介绍了如何找到数据库表中两个时间字段之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到以下错误



无法将参数值从DateTime转换为TimeSpan。



这是我的代码。

I get the following erro

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

This is my code.

Dim TimeOpened As DateTime = txtTimeOpened.Text
Dim TimeClosed As DateTime = txtTimeClosed.Text
Dim TimeElapsed As TimeSpan = TimeClosed - TimeOpened

cmd.Parameters.Add("@Status", OleDb.OleDbType.Char).Value = status
cmd.Parameters.Add("@DateClosed", OleDb.OleDbType.Date).Value = Today
cmd.Parameters.Add("@TimeOpened", OleDb.OleDbType.DBTime).Value = TimeOpened
cmd.Parameters.Add("@TimeClosed", OleDb.OleDbType.DBTime).Value = TimeClosed
cmd.Parameters.Add("@TimeElapsed", OleDb.OleDbType.DBTime).Value = TimeElapsed
cmd.Parameters.Add("@Param1", OleDb.OleDbType.Integer).Value = txtTicketNo.Text





可以帮助我一些人



can some one help me

推荐答案

Timespan不是DateTime - 你不能将一个转换为另一个。

所以你不能将DateTime传递给DBO用于TimeOpened或TimeClosed - 你需要将它们指定为Date值。
A Timespan is not a DateTime - and you can't convert the one to the other.
So you can't pass a DateTime to a DBTime for TimeOpened or TimeClosed - you need to specify them as Date values instead.


这篇关于如何找到数据库表中两个时间字段之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆