943,794 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 11560
  • VB.NET RSS
Feb 11th, 2006
0

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

Expand Post »
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"

VB.NET Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Texpert is offline Offline
14 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Quick VB2005 help....how do I get this basic app started?
Next Thread in VB.NET Forum Timeline: Problem with VB.NET and MS Access





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC