Help with System.Data.OleDb code...

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

I need another pair of eyes to look at this code. I am getting rows from
an OleDbDataReader from an Access 2002-2003 database.

...
If Not _reader Is Nothing Then
If _reader.HasRows Then
Dim _namePrefix As String = ""
Dim _ordinal As Int32
_ordinal = _reader.GetOrdinal("iNamePrefix")
If Not _reader.IsDBNull(_ordinal) Then
_namePrefix = _reader.GetString(_ordinal)
End If
...

The line "If Not _reader.IsDBNull(_ordinal) Then" is throwing an
InvalidOperationException (see below). The debugger says _ordinal is
correct (value is 1, which is as it should be - the 2nd column in the
SELECT * result set).

Any idea what I am doing wrong? It's probably something very simple that
I just can't see!

P.S. If it matters, the column in question is a Text column, length =
128, required = no, allow zero length = yes, default = "". I've tried
changing a few of these properties, but nothing seems to help.

TIA,

Dennis

***

System.InvalidOperationException was unhandled
Message="No data exists for the row/column."
Source="System.Data"
StackTrace:
at System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal)
at System.Data.OleDb.OleDbDataReader.IsDBNull(Int32 ordinal)
...
 
Remember.

While _reader.Read()



End While

You could do an "if" instead of while, if you know its 1 row, but I don't
like to do that, just in case.
 
Back
Top