声明时间 - “从类型‘Timespan’转换”输入“整数”;无效
我在代码中声明我的日期如下:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在客户端代码方面(您的 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 theDateTime
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.