Stumped on IsDBNull on SQLDataReader
-
Ok, this has me stumped. I am trying to get a single record from the DB, which may or may not be NULL.
Dim cmdSelect As New SqlCommand("SELECT weblink FROM dbo.environment WHERE id = 7, sqlDB) sqlDB.Open() sqlRead = cmdSelect.ExecuteReader If Not sqlRead.IsDBNull(0) Then '...Do something with result Else '...Do something with NULL End If
Yet when I do the test using'If Not sqlRead.IsDBNull(0) Then'
, it throws and error: Invalid attempt to read when no data is present. Yes, I know theres nothing there, thats what I am trying to test. I cant find anything about how this should work, all examples seem to expect data to be coming back. Help! -
Ok, this has me stumped. I am trying to get a single record from the DB, which may or may not be NULL.
Dim cmdSelect As New SqlCommand("SELECT weblink FROM dbo.environment WHERE id = 7, sqlDB) sqlDB.Open() sqlRead = cmdSelect.ExecuteReader If Not sqlRead.IsDBNull(0) Then '...Do something with result Else '...Do something with NULL End If
Yet when I do the test using'If Not sqlRead.IsDBNull(0) Then'
, it throws and error: Invalid attempt to read when no data is present. Yes, I know theres nothing there, thats what I am trying to test. I cant find anything about how this should work, all examples seem to expect data to be coming back. Help!You must call
sqlRead.Read()
first. Kelly Herald Software Developer MPC -
You must call
sqlRead.Read()
first. Kelly Herald Software Developer MPC