Texpert 0 Newbie Poster

Hi,

in the .NET 1.1 and VB application, I am calling a store procedure [SQL-SERVER 2000] in a subroutine. the store procedure simply SELECTs rows from tables and returns data, when I try to use the data to fill the web form, it works fine until it hits any column with NULL value. When NULL column it throws an exception and does not fill rest of the columns. in the debug window I get the following error
"Data is Null. This method or property cannot be called on Null values"

Public Sub ReadMyData()
        Dim MySelectQuery As String
        Dim MyConn As SqlConnection
        Dim Mycmd As SqlCommand
        Dim MyReader As SqlDataReader

        Dim objParam1 As SqlParameter

        Try
            MyConn = New SqlConnection(ConfigurationSettings.AppSettings("Conn"))
            If MyConn.State = ConnectionState.Closed Then
                MyConn.Open()
            End If

            Mycmd = New SqlCommand("sp_SelectReleaseDetails", MyConn)
            Mycmd.CommandType = CommandType.StoredProcedure

            objParam1 = Mycmd.Parameters.Add("@PX_Release_Id", SqlDbType.Int)
            objParam1.Value = PX_REL_ID.Text.Trim

            MyReader = Mycmd.ExecuteReader()

            MyReader.Read()

          Release_Label.Text = MyReader.GetString(0) ' LabelID,
          Release_Artist.Text = MyReader.GetString(1) 'ReleaseArtist,
          ..
          ..
          ...

            MyReader.Close()
            Mycmd.Dispose()
            MyConn.Dispose()

            MyConn.Close()


        Catch ex As Exception
            System.Diagnostics.Trace.WriteLine("[ReadMyData] Exception " & ex.Message)
        Catch exp As SqlException
            DisplaySqlErrors(exp)
        Finally
            MyConn.Close()

        End Try



    End Sub

I have tried "IsDBNull", IsNull, "= Nothing" all ways to catch this condition. All I want it to simply accept the null values and move ahead.

Now I can think of changing the null in store procedure into some strings just as a work around.
But want to know what is a proper way to handle this situation in VB.

thanks.

Tejoo.
:?:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.