Click here to Skip to main content
Sign Up to vote bad
good
See more: VB.NET
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
            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 23 Nov '12 - 0:56
Edited 23 Nov '12 - 1:59
__TR__28.5K

Comments
Annnaa - 23 Nov '12 - 7:12
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")

2 solutions

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
  Permalink  
Comments
Annnaa - 23 Nov '12 - 8:16
what about if i want to create e previews button?
Krunal R - 23 Nov '12 - 8:21
Like ???
Annnaa - 23 Nov '12 - 8:28
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
Krunal R - 23 Nov '12 - 8:33
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)

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 508
1 Arun Vasu 315
2 Maciej Los 218
3 OriginalGriff 205
4 Aarti Meswania 170
0 Sergey Alexandrovich Kryukov 9,670
1 OriginalGriff 7,409
2 CPallini 3,968
3 Rohan Leuva 3,352
4 Maciej Los 2,861


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid