[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

DataReader error using .Net ODBC

Yan Zang

1/21/2003 9:00:00 PM

Hi,

I am trying to use .Net ODBC to read data from a legacy ODBC data store. The
legacy ODBC driver works OK when I access it using classic ASP. When I use
.Net, the connection and dataReader are opened, but I got the following
error at the line when the data is read

An unhandled exception of type 'System.IndexOutOfRangeException' occurred in
microsoft.data.odbc.dll

Additional information: NAME

The code is attached. Any ideas? Thanks!

Yan

----------------------------------------------------------------------------
---------

mstrSQL_in = "SELECT * from CLIENTS where CODE='1006'"

mobjBuilder_in = New OdbcCommand(mstrSQL_in, mobjConnection_in)

mobjDataReader_in = mobjBuilder_in.ExecuteReader()

MsgBox("reader opened")

While (mobjDataReader_in.Read() = True)

Name = mobjDataReader_in("NAME") ************** error line
****************

end while


3 Answers

(Steven Bras [MS])

1/21/2003 11:42:00 PM

0

I believe it's complaining about the field name; try using the index of the
field instead (the zero-based ordinal position of the column in the table).
If this doesn't work, check the DataReader object's FieldCount property. If
this is zero, then the problem is most likely with the command object and
not the data reader. Post these details and I'll do my best to assist.

Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co....


Yan Zang

1/22/2003 1:05:00 AM

0

Thanks, Steven.

I used index, and it got better. However, I got a new error as below

-----
An unhandled exception of type 'Microsoft.Data.Odbc.OdbcException' occurred
in microsoft.data.odbc.dll

Additional information: System error.
-----

Code attached. Thanks! By the way, fieldCount is greater than 1.

Yan

-----------------------------------------------------
Attached code

mobjBuilder_in = New OdbcCommand(mstrSQL_in, mobjConnection_in)
mobjDataReader_in = mobjBuilder_in.ExecuteReader()

While (mobjDataReader_in.Read() = True)

Name = mobjDataReader_in(0)

Code = mobjDataReader_in(1)

Address = mobjDataReader_in(2)

City = mobjDataReader_in(3) ******* error line
**********************

end while

-----------------------------------------------------------

"Steven Bras [MS]" <stevenbr@online.microsoft.com> w
rote in message news:2vduj5ZwCHA.2600@cpmsftngxa06...
> I believe it's complaining about the field name; try using the index of
the
> field instead (the zero-based ordinal position of the column in the
table).
> If this doesn't work, check the DataReader object's FieldCount property.
If
> this is zero, then the problem is most likely with the command object and
> not the data reader. Post these details and I'll do my best to assist.
>
> Steven Bras, MCSD
> Microsoft Developer Support/Visual Basic WebData
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> Are you secure? For information about the Microsoft Strategic Technology
> Protection Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.co....
>
>


Yan Zang

1/22/2003 1:40:00 AM

0

I found out that if a field has null (or empty) data, it will generate the
'unhandled exception'. The exception occurs even if this null field is not
read from the dataReader. All following fields will give the same err when
read from DataReader. How to get around it?

Yan

"Yan Zang" <yan_zang@hotmail.com> wrote in message
news:OZp0SoawCHA.1712@TK2MSFTNGP10...
> Thanks, Steven.
>
> I used index, and it got better. However, I got a new error as below
>
> -----
> An unhandled exception of type 'Microsoft.Data.Odbc.OdbcException'
occurred
> in microsoft.data.odbc.dll
>
> Additional information: System error.
> -----
>
> Code attached. Thanks! By the way, fieldCount is greater than 1.
>
> Yan
>
> -----------------------------------------------------
> Attached code
>
> mobjBuilder_in = New OdbcCommand(mstrSQL_in, mobjConnection_in)
> mobjDataReader_in = mobjBuilder_in.ExecuteReader()
>
> While (mobjDataReader_in.Read() = True)
>
> Name = mobjDataReader_in(0)
>
> Code = mobjDataReader_in(1)
>
> Address = mobjDataReader_in(2)
>
> City = mobjDataReader_in(3) ******* error line
> **********************
>
> end while
>
> -----------------------------------------------------------
>
> "Steven Bras [MS]" <stevenbr@online.microsoft.com> w
> rote in message news:2vduj5ZwCHA.2600@cpmsftngxa06...
> > I believe it's complaining about the field name; try using the index of
> the
> > field instead (the zero-based ordinal position of the column in the
> table).
> > If this doesn't work, check the DataReader object's FieldCount property.
> If
> > this is zero, then the problem is most likely with the command object
and
> > not the data reader. Post these details and I'll do my best to assist.
> >
> > Steven Bras, MCSD
> > Microsoft Developer Support/Visual Basic WebData
> >
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> >
> > Are you secure? For information about the Microsoft Strategic Technology
> > Protection Program and to order your FREE Security Tool Kit, please
visit
> > http://www.microsoft.co....
> >
> >
>
>