locked
SQL - check whether it is no record, null value or string value RRS feed

  • Question

  • User363578564 posted

    I wish to check the result which may be no record, null value or string value

    Null error if it is assigned to a variable.

    is it necessary to run the query thrice?  it seems not very clever.  Thanks a lot.

            Dim SQL_Valid As SqlCommand = New SqlCommand("Select ABC from Table where id=4753", SQLCS)
            If IsDBNull(SQL_Valid.ExecuteScalar) Then
                MsgBox("Field is null")
            ElseIf SQL_Valid.ExecuteScalar Is Nothing Then
                MsgBox("No record")
            Else
                MsgBox(SQL_Valid.ExecuteScalar)
            End If

    Wednesday, December 20, 2017 3:32 AM

Answers

  • User363578564 posted

    use isnull

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 20, 2017 3:53 AM