10

I've been struggling for the past few hours and still can't get my head round this one . The issue I am having is when someone has been admitted the database updates giving them BedID , when I then try and discharge them I can't seem to set the BedID (In the database) to nothing . This is an issue as I need to be able to admit and discharge as many people as I can.

Sub Dis1_Click(ByVal s As Object, ByVal e As EventArgs) Handles Dis1.ServerClick

    Dim time As String = Now().ToString("dd-MM-yyyy hh:mm:ss")

    sql = "UPDATE Allocation  SET BedID = NULL , DischargeDate =" + "'" + time + "'" + " WHERE BedID = 1 "
    cmd = New OdbcCommand(sql, cn)
    cmd.ExecuteNonQuery()
End Sub

Sub BedCheck1()
    If r("BedID") = "" Then
    Else
        If r("BedID") = 1 Then
            ba = s & "<tr><td>" & r("Surname") & "</td>" & "<td>" & r("Forename") & "/<td>" & "<td>" & r("AdmitDate") & "</td>" & "<td>" & r("DischargeDate") & "</td>" & "<td>" & r("comments") & "</td></tr>"
        End If
    End If
End Sub

Thanks!

4

3 回答 3

23

在读取值之前,您需要进行 DbNull 检查:

If Not IsDbNull(r("BedID")) Then

    If r("BedID") = "" Then
    Else If r("BedID") = 1 Then
        ba = s & "<tr><td>" & r("Surname") & "</td>" & "<td>" & r("Forename") & "/<td>" & "<td>" & r("AdmitDate") & "</td>" & "<td>" & r("DischargeDate") & "</td>" & "<td>" & r("comments") & "</td></tr>"
    End If
End If

请注意,DbNull 是一种特殊情况,您需要使用 IsDbNull 函数来防止此错误

于 2013-04-17T23:20:27.663 回答
2

试试这个:如果 r("BedID").ToString = " " 那么

万一

于 2018-11-28T11:54:22.023 回答
0

好吧,在检查数据验证之前,您需要检查它是否为 DB null。

If Not IsDbNull(r("BedID")) Then
your code
End if 
于 2018-05-08T10:46:30.543 回答