Click here to Skip to main content
13,352,157 members (76,780 online)

How to loop through records in a datatable?

lovitaxxxx asked:

Open original thread
I want to loop through the records of the datatable and retrieve data from the each column of the datatableand fill the textboxes.
what should i do to moveNext button?
I have tried :
Protected Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click

        Dim i As Integer = 0

        For i = 0 To MaxRows
            i = i + 1

End Sub

Where  :
 MaxRows = tb.Rows.Count

 Private Sub NavigateRecords(int As Integer)

        Dim conn As New OleDb.OleDbConnection
        Dim strConn As String = "Provider=SQLOLEDB; Data Source=; Initial Catalog=; User ID=; Password="

        conn.ConnectionString = strConn

        Dim dst As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim tb As DataTable = dst.Tables("Client")

        Sqll = "SELECT * FROM Person"

        da = New OleDb.OleDbDataAdapter(Sqll, conn)
        da.Fill(dst, "Customer")
 MaxRows = tb.Rows.Count
       txt_vl.Value = tb.Rows(int).Item("value")

[Edit]Added code based on OP's comment[/Edit]
Tags: VB, VB.NET


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100