473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help with System.Data.OleDb code...

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(Int 32 ordinal)
at System.Data.OleDb.OleDbDataReader.IsDBNull(Int32 ordinal)
...
Jun 30 '08 #1
2 2620
Never mind. I new it was something dumb (like a missing _reader.Read).

Dennis

--

On Mon, 30 Jun 2008 18:41:33 -0400, Dennis <no****@nowhere.comwrote:
>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(Int 32 ordinal)
at System.Data.OleDb.OleDbDataReader.IsDBNull(Int32 ordinal)
...
Jun 30 '08 #2
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" <no****@nowhere.comwrote in message
news:ph********************************@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 <no****@nowhere.comwrote:
>>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(Int 32 ordinal)
at System.Data.OleDb.OleDbDataReader.IsDBNull(Int32 ordinal)
...

Jul 1 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: roopeman | last post by:
i need your help, my code as below : //----------------------------------------------------------------------- //Wrote by Michael April 30 2005...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
4
by: shachar | last post by:
hi all(i tried yesterday but it didnt work). i wrote this code and i get an error msg: Private Pr_MyCon As System.Data.OleDb.OleDbConnection Private Pr_DataSet As DataSet Private Pr_DataAdapter...
11
by: CM Manager via DotNetMonster.com | last post by:
I am very frustrated due to this exception error I am receiving. I've tried searching numerous user support groups, Microsoft Support Net, Google, etc. and haven't found exactly my situation....
3
by: John Cosmas | last post by:
I have a DATATABLE which I have populated in my application, and I need it written out to a particular table I specify in my ACCESS database. My code works to the point of the MERGE and UPDATE,...
4
by: Ron | last post by:
I am having a bit of problem with this code: Dim cmd As New OleDb.OleDbCommand("INSERT INTO help (Name, Email, telephone, description)VALUES('" & txtName.Text & "','" & txtEmail.Text & "','" &...
9
by: TF | last post by:
Hello all, I made a ASP.NET 2.0 site that shows possible "recipes" for paint colors stored in an access dbase. Basically, 1000 colors are stored with specific RGB values in separate columns. A...
2
by: johnmay1248 | last post by:
I am having a problem with queries running in this code When I use the query "SELECT * FROM sample" the code runs and the data grid binds and shows the contents of the sample table. If I change...
3
by: amjad905 | last post by:
Hi, I have created some dynamic labels and some dynamic linkbuttons... those linkbuttons have addhandlers assigned to them... but in postback those buttons gets deleted... the code is shown...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.