I'm using the code pasted below to return a single value from SQL (in .NET 2003).
If STR_BGC_ZONE is null, I get an error "Object reference not set to an instance of an object." when the executeScalar line is called.
Is there some way to code around this?
Try
Dim strConn As String = SqlDbManager.GetConnectionString
Dim strSQL As String = "SELECT TOP 1 STR_BGC_ZONE FROM TDT_CUT_BLOCK_ECO_UNIT WHERE '" & SPID & "' = ID_SILV_PRES AND '" & SU & "' = STR_STANDARDS_UNIT"
Dim Conn As New SqlConnection(strConn)
Dim Cmd As New SqlCommand(strSQL, Conn)
Conn.Open()
BECzone = Cmd.ExecuteScalar.ToString
Conn.Close()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
Thanks!
Amber
If STR_BGC_ZONE is null, I get an error "Object reference not set to an instance of an object." when the executeScalar line is called.
Is there some way to code around this?
Try
Dim strConn As String = SqlDbManager.GetConnectionString
Dim strSQL As String = "SELECT TOP 1 STR_BGC_ZONE FROM TDT_CUT_BLOCK_ECO_UNIT WHERE '" & SPID & "' = ID_SILV_PRES AND '" & SU & "' = STR_STANDARDS_UNIT"
Dim Conn As New SqlConnection(strConn)
Dim Cmd As New SqlCommand(strSQL, Conn)
Conn.Open()
BECzone = Cmd.ExecuteScalar.ToString
Conn.Close()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
Thanks!
Amber