N
NumbLock
Hello all. I have a bit of code that to me looks perfectly sane, but the
VB IDE flags a warning. I was wondering if this is just a limitation of
the code parser that the IDE uses or is it a bad practice. Here is the code
(I know the purists will bitch about the goto but I've been coding VB since
version 3 even VB-DOS if anyone remembers it but I am still a tad lazy):
Dim oCmd As New SqlCommand("usp_GetCustomerAddressBlock", oCn)
oCmd.CommandType = CommandType.StoredProcedure
oCmd.Parameters.AddWithValue("@ListID", ComboBoxCompanyName.SelectedValue)
Dim oReader As SqlDataReader
Try
oReader = oCmd.ExecuteReader
Catch ex As Exception
Call oUtil.SetStatusMessage(String.Format("There was an error
retrieving the customer's billing address. {0}", ex.Message), , True)
GoTo cleanup
End Try
If Not oReader.HasRows Then
Call oUtil.SetStatusMessage("There is no address information
available for this customer.", True)
GoTo cleanup
End If
oReader.Read()
Me.TextBoxCustomerBillingAddress.Text = oReader!BillingAddress
Me.TextBoxShippingAddress.Text = oReader!ShippingAddress
cleanup:
If Not IsNothing(oReader) Then
oReader.Close()
oReader.Dispose()
End If
oCmd.Dispose()
oCn.Close()
oCn.Dispose()
it is flagging the null exception warning on the following line:
If Not IsNothing(oReader) Then
Thanks for any advice.
VB IDE flags a warning. I was wondering if this is just a limitation of
the code parser that the IDE uses or is it a bad practice. Here is the code
(I know the purists will bitch about the goto but I've been coding VB since
version 3 even VB-DOS if anyone remembers it but I am still a tad lazy):
Dim oCmd As New SqlCommand("usp_GetCustomerAddressBlock", oCn)
oCmd.CommandType = CommandType.StoredProcedure
oCmd.Parameters.AddWithValue("@ListID", ComboBoxCompanyName.SelectedValue)
Dim oReader As SqlDataReader
Try
oReader = oCmd.ExecuteReader
Catch ex As Exception
Call oUtil.SetStatusMessage(String.Format("There was an error
retrieving the customer's billing address. {0}", ex.Message), , True)
GoTo cleanup
End Try
If Not oReader.HasRows Then
Call oUtil.SetStatusMessage("There is no address information
available for this customer.", True)
GoTo cleanup
End If
oReader.Read()
Me.TextBoxCustomerBillingAddress.Text = oReader!BillingAddress
Me.TextBoxShippingAddress.Text = oReader!ShippingAddress
cleanup:
If Not IsNothing(oReader) Then
oReader.Close()
oReader.Dispose()
End If
oCmd.Dispose()
oCn.Close()
oCn.Dispose()
it is flagging the null exception warning on the following line:
If Not IsNothing(oReader) Then
Thanks for any advice.