Exception Data is Null. This method or property cannot be called on Null values.

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2006
Posts: 14
Reputation: Texpert is an unknown quantity at this point 
Solved Threads: 0
Texpert's Avatar
Texpert Texpert is offline Offline
Newbie Poster

Exception Data is Null. This method or property cannot be called on Null values.

 
0
  #1
Feb 11th, 2006
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"

  1. Public Sub ReadMyData()
  2. Dim MySelectQuery As String
  3. Dim MyConn As SqlConnection
  4. Dim Mycmd As SqlCommand
  5. Dim MyReader As SqlDataReader
  6.  
  7. Dim objParam1 As SqlParameter
  8.  
  9. Try
  10. MyConn = New SqlConnection(ConfigurationSettings.AppSettings("Conn"))
  11. If MyConn.State = ConnectionState.Closed Then
  12. MyConn.Open()
  13. End If
  14.  
  15. Mycmd = New SqlCommand("sp_SelectReleaseDetails", MyConn)
  16. Mycmd.CommandType = CommandType.StoredProcedure
  17.  
  18. objParam1 = Mycmd.Parameters.Add("@PX_Release_Id", SqlDbType.Int)
  19. objParam1.Value = PX_REL_ID.Text.Trim
  20.  
  21. MyReader = Mycmd.ExecuteReader()
  22.  
  23. MyReader.Read()
  24.  
  25. Release_Label.Text = MyReader.GetString(0) ' LabelID,
  26. Release_Artist.Text = MyReader.GetString(1) 'ReleaseArtist,
  27. ..
  28. ..
  29. ...
  30.  
  31. MyReader.Close()
  32. Mycmd.Dispose()
  33. MyConn.Dispose()
  34.  
  35. MyConn.Close()
  36.  
  37.  
  38. Catch ex As Exception
  39. System.Diagnostics.Trace.WriteLine("[ReadMyData] Exception " & ex.Message)
  40. Catch exp As SqlException
  41. DisplaySqlErrors(exp)
  42. Finally
  43. MyConn.Close()
  44.  
  45. End Try
  46.  
  47.  
  48.  
  49. 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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC