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!
The DBNull class represents a nonexistent value. In a database, for example, a column in a row of a table might not contain any data whatsoever. That is, the column is considered to not exist at all instead of merely not having a value. A DBNull object represents the nonexistent column.
It just means that the item has no value, so you need to test for DBNull before trying to add it to the ListView .
You need to do a DbNull-check before you read the value:
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
Note that DbNull is a special case and you need to use the IsDbNull-function to prevent this error
Try this: if r("BedID").ToString = " " then
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With