A
Andrew Baker
I have the following code that calles a stored proc in SQLServer. When the
output parameter @custref is null (System.DBNull) I cant seem to find a
test for this and I get an exception. I know I could coalesce the stored
proc, but I would like to know if the value is null.
How do you test for null in the returned parameter of a stored proc?
TIA
Andrew.
Dim retstr As String = ""
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(Me.sSqlString)
Dim myCommand As SqlCommand = New SqlCommand("bo_getCustRef", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterCode As SqlParameter = New SqlParameter("@CustCode",
SqlDbType.NVarChar, 8)
parameterCode.Value = code
myCommand.Parameters.Add(parameterCode)
Dim parameterRef As SqlParameter = New SqlParameter("@custRef",
SqlDbType.NVarChar, 20)
parameterRef.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterRef)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch XcpInvOp As System.Exception
Finally
myConnection.Close()
myConnection.Dispose()
myConnection = Nothing
If Not parameterRef.Value Is Nothing Then
retstr = CStr(parameterRef.Value)
End If
End Try
Return retstr
output parameter @custref is null (System.DBNull) I cant seem to find a
test for this and I get an exception. I know I could coalesce the stored
proc, but I would like to know if the value is null.
How do you test for null in the returned parameter of a stored proc?
TIA
Andrew.
Dim retstr As String = ""
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(Me.sSqlString)
Dim myCommand As SqlCommand = New SqlCommand("bo_getCustRef", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterCode As SqlParameter = New SqlParameter("@CustCode",
SqlDbType.NVarChar, 8)
parameterCode.Value = code
myCommand.Parameters.Add(parameterCode)
Dim parameterRef As SqlParameter = New SqlParameter("@custRef",
SqlDbType.NVarChar, 20)
parameterRef.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterRef)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch XcpInvOp As System.Exception
Finally
myConnection.Close()
myConnection.Dispose()
myConnection = Nothing
If Not parameterRef.Value Is Nothing Then
retstr = CStr(parameterRef.Value)
End If
End Try
Return retstr