Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 310372 - Last Review: May 13, 2007 - Revision: 3.2
DataTable and DataView do not include MoveFirst, MoveLast, MoveNext, and MovePrevious navigation methods
This article was previously published under Q310372
This article refers to the following Microsoft .NET Framework Class Library namespace:
On This Page
SYMPTOMS
In Microsoft ActiveX Data Objects (ADO), you can use the
MoveFirst, the
MoveLast, the
MoveNext, and the
MovePrevious methods to navigate through your recordset. However, ADO.NET does not include these navigation methods.
CAUSE
Because a
DataTable object is always in memory, ADO.NET does not require cursor access. ADO.NET uses array access instead.
RESOLUTION
To access a row in a
DataTable, use one of the following methods:
- Reference the row number directly.
- If you use data binding, use the CurrencyManager class.
- Use the For Each...Next Microsoft Visual Basic .NET statement or the foreach Microsoft Visual C# .NET statement to enumerate the rows.
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce the Behavior
- Start Microsoft Visual Studio .NET.
- Create a new Windows Application project in Visual Basic .NET. Form1 is added to the project by default.
- Make sure that your project contains a reference to the System.Data namespace.
- Add a Button control to Form1. Change the Name property of the button to btnTest, and then change the Text property to Test.
- Use the Imports statement on the System and the System.Data namespaces so that you are not required to qualify declarations in those namespaces later in your code. Add the following code to the "General Declarations" section of Form1:
Imports System
Imports System.Data
Imports System.Data.SqlClient
- Add the following code in the btnTest event:
Dim ds As New DataSet()
Dim da As SqlDataAdapter
Dim cn As New SqlConnection("server=myserver;integrated security=sspi;" & _
"database=northwind")
da = New SqlDataAdapter("select * from customers", cn)
da.Fill(ds, "customers")
Dim x As Integer
'Forward
For x = 1 To ds.Tables(0).Rows.Count - 1
Console.WriteLine(ds.Tables(0).Rows(x).Item("customerid").ToString)
Next
'Backward
For x = ds.Tables(0).Rows.Count - 1 To 1 Step -1
Console.WriteLine((ds.Tables(0).Rows(x).Item("customerid").ToString))
Next
- Modify the connection string as appropriate for your environment.
- Save and run the project.
- Click Test. Notice the output in the output window.
REFERENCES
For more information about the
CurrencyManager class, refer to the following MSDN Web site:
APPLIES TO
- Microsoft ADO.NET 1.0
- Microsoft ADO.NET 1.1
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual Basic .NET 2003 Standard Edition
| kbprb kbsqlclient kbsystemdata KB310372 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
santosh
- shukla_santosh2004
|
|
| Written:
9/10/2004 2:04 AM |
|
|
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please