从'Boolean'到'DateTime'的无效演员表

时间:2013-11-04 09:37:23

标签: vb.net

我一直收到此错误

  

从'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

1 个答案:

答案 0 :(得分:3)

错误在这一行:

Dim forupdate As Date = Convert.ToDateTime(closedate < todayDate)

closedate < todayDate会返回truefalse,具体取决于closedate是否在todayDate之前。

该值无法转换为DateTime,这就是异常所说的。也许你需要重新考虑这条线应该做什么。