Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
VB
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
            NavigateRecords(i)

        Next
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

        conn.Open()
        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]
Posted
Updated 23-Nov-12 1:59am
v2
Comments
lovitaxxxx 23-Nov-12 7:12am    
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
NavigateRecords(i)

Next
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

conn.Open()
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")

loop through all records:
Dim table As DataTable = GetTable
' Get the data table.
For Each row As DataRow In table.Rows
    Console.WriteLine("--- Row ---")
    ' Print separator.
    For Each item As var In row.ItemArray
        Console.Write("Item: ")
        ' Print label.
        Console.WriteLine(item)
        ' Invokes ToString abstract method.
    Next
Next
Console.Read
 
Share this answer
 
Comments
lovitaxxxx 23-Nov-12 8:16am    
what about if i want to create e previews button?
[no name] 23-Nov-12 8:21am    
Like ???
lovitaxxxx 23-Nov-12 8:28am    
for example:
Protected Sub btn_previews_Click(sender As Object, e As EventArgs) Handles btn_previews.Click

If (i > 0) Then

i = i - 1


NavigateRecords(i)
End If
End Sub
[no name] 23-Nov-12 8:33am    
Okay, do this: I'm assuming that now you're able to go through each row ok.. So get the each row make the row as selected using currentRow-1... (Actually I'm not much good in VB .NET like C# .NET.. So I can help you with C# code)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900