Error message when you use DataReader in Visual Basic .NET: "Invalid attempt to read from column ordinal" (308069)
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft Visual Basic .NET (2002)
This article was previously published under Q308069 For a Microsoft Visual C# .NET version of this article, see 308614.
This article refers to the following Microsoft .NET Framework Class Library namespace:
SYMPTOMS
When you use DataReader to read a row, if you try to access columns in that row, you receive an error message similar to the following:
System.InvalidOperationException: Invalid attempt to read from column ordinal '0'. With CommandBehavior.SequentialAccess, you may only read from column ordinal '2' or greater.
CAUSE
This problem occurs because you executed OleDbCommand or SqlCommand with the System.Data.CommandBehavior.SequentialAccess flag set but did not access the columns sequentially.
RESOLUTION
Use one of the following methods to work around this problem:
- Read each column only once and in the sequence in which it is defined by the SELECT query.
NOTE: For performance reasons, which are listed in the "More Information" section, this is the preferred resolution. - Do not use CommandBehavior.SequentialAccess. If you do not use CommandBehavior.SequentialAccess, you can access a column in a row twice and read columns out of sequence.
STATUSThis behavior is by design.REFERENCES
For more information, see the "SequentialAccess enumeration member" topic in the index in Visual Studio .NET Online Help.
Modification Type: | Minor | Last Reviewed: | 3/9/2006 |
---|
Keywords: | kbDatabase kbprb kbSqlClient kbSystemData KB308069 kbAudDeveloper |
---|
|