我一直收到此错误
从'Boolean'到'DateTime'的无效演员
当下面的代码尝试执行时。
我基本上是在尝试更新我的auction_item表,其中满足“closedate< todayDate”。
这是错误触发的地方[Dim forupdate As Date = Convert.ToDateTime(closedate< todayDate)]
con.Open()
CMD = New SqlCommand("SELECT auction_item_close_date FROM auction_items WHERE (auction_item_status_id = 1)", con)
DR = CMD.ExecuteReader()
DR.Read()
Dim closedate As Date
closedate = Convert.ToDateTime(DR(0))
con.Close()
Dim todayDate As Date = DateAndTime.Today
Dim forupdate As Date = Convert.ToDateTime(closedate < todayDate)
con.Open()
If closedate < todayDate Then
SQL = "UPDATE auction_items SET auction_item_status_id = 2, auction_item_open_closed = 'closed' WHERE auction_item_close_date = '" & forupdate & "'"
CMD = New SqlCommand(SQL, con)
CMD.ExecuteNonQuery()
con.Close()
End If
答案 0 :(得分:3)
错误在这一行:
Dim forupdate As Date = Convert.ToDateTime(closedate < todayDate)
closedate < todayDate
会返回true
或false
,具体取决于closedate
是否在todayDate
之前。
该值无法转换为DateTime
,这就是异常所说的。也许你需要重新考虑这条线应该做什么。