Microsoft Knowledge Base Email Alertz

KBAlertz.com: In Microsoft ActiveX Data Objects (ADO), you can use the

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








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:
  • System.Data.SqlClient

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

  1. Start Microsoft Visual Studio .NET.
  2. Create a new Windows Application project in Visual Basic .NET. Form1 is added to the project by default.
  3. Make sure that your project contains a reference to the System.Data namespace.
  4. Add a Button control to Form1. Change the Name property of the button to btnTest, and then change the Text property to Test.
  5. 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
    					
  6. 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
    					
  7. Modify the connection string as appropriate for your environment.
  8. Save and run the project.
  9. Click Test. Notice the output in the output window.

REFERENCES

For more information about the CurrencyManager class, refer to the following MSDN Web site:
CurrencyManager Class
http://msdn2.microsoft.com/en-us/library/system.windows.forms.currencymanager(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.windows.forms.currencymanager(vs.71).aspx)

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
Keywords: 
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
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cnn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" _
        & "Datasource=" & AppDomain.CurrentDomain.BaseDirectory & _
        "PhoneBook.mdb")
        Dim cmdph As New OleDb.OleDbCommand()

        cmdph = cnn.CreateCommand
        cmdph.CommandText = "Select * from Contacts"
        dacus.SelectCommand = cmdph
        Dim cb As OleDb.OleDbCommandBuilder = _
        New OleDb.OleDbCommandBuilder(dacus)
        dacus.Fill(dscus, "Contacts")
        t1.DataBindings.Add("Text", dscus.Tables("Contacts"), "ContactID")
        t2.DataBindings.Add("Text", dscus.Tables("Contacts"), "Name")
        t3.DataBindings.Add("Text", dscus.Tables("Contacts"), "Address")


    End Sub

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please