未为类型“DBNull"和类型“整数"定义运算符“=" [英] Operator '=' is not defined for type 'DBNull' and type 'Integer'

查看:25
本文介绍了未为类型“DBNull"和类型“整数"定义运算符“="的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几个小时我一直在挣扎,但仍然无法理解这一点.我遇到的问题是,当有人被承认数据库更新给他们 BedID 时,当我尝试释放他们时,我似乎无法将 BedID(在数据库中)设置为 nothing .这是一个问题,因为我需要能够接纳和释放尽可能多的人.

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

谢谢!

推荐答案

在读取值之前需要做一个 DbNull-check:

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

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

Note that DbNull is a special case and you need to use the IsDbNull-function to prevent this error

这篇关于未为类型“DBNull"和类型“整数"定义运算符“="的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆