声明时间 - “从类型‘Timespan’转换”输入“整数”;无效

发布于 2025-01-07 08:00:38 字数 781 浏览 0 评论 0原文

我在代码中声明我的日期如下:

Dim DeliveryDate as Date

但我现在尝试声明时间,但是我不断收到错误,因为我无法获得正确的类型。我尝试了以下操作,但出现以下错误:“从‘Timespan’类型到‘integer’类型的转换无效”。

Dim DeliveryTime as DateTime
Dim DeliveryTime as Integer

在我的数据库中,DeliveryTime 类型设置为 Time(7),因此我假设应该有“Time”,我可以用它来声明它,但没有。我应该使用的正确类型是什么?


这是我的确切代码。错误是输入字符串的格式不正确

GraphDate4 = String.Empty 
DeliveryProducts = "{ name: 'DeliveryProducts', data: [" 
If DataReader4.HasRows Then 
    While DataReader4.Read 
        Dim DevTime As Timespan = DataReader4("DeliveryTime") 
        GraphDate4 += """" + DevilTime.ToString("d") + """," 
        DeliveryProducts += DataReader4("DeliveryProducts").ToString() + "," 
    End While 
End If 

I declare my dates as the following in my code:

Dim DeliveryDate as Date

But i am now trying to declare time however i keep getting an error because i cannot get the type correct. I tried the following but get the following error: "Conversion from type 'Timespan' to type 'integer' is not valid".

Dim DeliveryTime as DateTime
Dim DeliveryTime as Integer

In my database the DeliveryTime type is set to Time(7) so i would assume there should be 'Time' which i could use to declare it, but there isnt. What is the correct type i should be using?


Here is my exact code. There error is Input string was not in correct format:

GraphDate4 = String.Empty 
DeliveryProducts = "{ name: 'DeliveryProducts', data: [" 
If DataReader4.HasRows Then 
    While DataReader4.Read 
        Dim DevTime As Timespan = DataReader4("DeliveryTime") 
        GraphDate4 += """" + DevilTime.ToString("d") + """," 
        DeliveryProducts += DataReader4("DeliveryProducts").ToString() + "," 
    End While 
End If 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒岛晴空 2025-01-14 08:00:38

在客户端代码方面(您的 vb.net 代码),Date 数据类型实际上是 DateTime 数据类型的别名,其中包括两者的组件日期和时间具有相同的值。

但在这里,听起来也许您只需要一个 TimeSpan 数据类型,并使用 TimeSpan 的 FromSeconds() 或 FromMilliseconds() 方法来构造它。

On the client-code side of things (your vb.net code), the Date data type is really an alias for the DateTime data type, which includes a component for both date and time in the same value.

But here, it sounds like maybe you just need a TimeSpan data type, and use TimeSpan's FromSeconds() or FromMilliseconds() methods to construct it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文