|
From: Dennis on 30 Jun 2008 18:41 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) ...
From: Dennis on 30 Jun 2008 19:21 Never mind. I new it was something dumb (like a missing _reader.Read). Dennis -- On Mon, 30 Jun 2008 18:41:33 -0400, Dennis <nobody(a)nowhere.com> wrote: >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) > ...
From: sloan on 1 Jul 2008 14:09 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. "Dennis" <nobody(a)nowhere.com> wrote in message news:phqi64he1jgfkrral219493g8cau9ujsbm(a)4ax.com... > Never mind. I new it was something dumb (like a missing _reader.Read). > > Dennis > > -- > > On Mon, 30 Jun 2008 18:41:33 -0400, Dennis <nobody(a)nowhere.com> wrote: > >>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) >> ...
|
Pages: 1 Prev: Using query string Next: validating if a file is a true valid xml file that fits a cert |