This code creates XML File

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connetionString As String
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim ds As New DataSet
        Dim sql As String

        connetionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Danial\documents\visual studio 2010\Projects\ESI_PF_Payroll_V1\ESI_PF_Payroll_V1\Pay.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        connection = New SqlConnection(connetionString)
        sql = "select * from Acc"
        Try
            If IO.File.Exists("Testimage.xml") = False Then
                connection.Open()
                adapter = New SqlDataAdapter(sql, connection)
                adapter.Fill(ds)
                connection.Close()
                ds.WriteXml("Testimage.xml")
                MsgBox("File Created")
            Else
                MsgBox("File Already Exists")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

This Code read file and sends it's contents to textbox(es)

Dim xmlFile As XmlReader
        xmlFile = XmlReader.Create("Testimage.xml", New XmlReaderSettings())
        Dim ds As New DataSet
        While ds.ReadXml(xmlFile)
            Dim i As Integer
            For i = 0 To ds.Tables(0).Rows.Count - 1
                TextBox1.Text = (ds.Tables(0).Rows(i).Item(1))
                TextBox2.Text = (ds.Tables(0).Rows(i).Item(2))
                TextBox3.Text = (ds.Tables(0).Rows(i).Item(3))
                TextBox4.Text = (ds.Tables(0).Rows(i).Item(4))
                TextBox5.Text = (ds.Tables(0).Rows(i).Item(5))
                TextBox6.Text = (ds.Tables(0).Rows(i).Item(6))
                TextBox7.Text = (ds.Tables(0).Rows(i).Item(7))
                TextBox8.Text = (ds.Tables(0).Rows(i).Item(8))
                TextBox9.Text = (ds.Tables(0).Rows(i).Item(9))
            Next
        End While
End Sub

This code navigate records ...and needs help

 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim nav As XPathNavigator
        Dim docNav As XPathDocument
        docNav = New XPathDocument("Testimage.xml")
        nav = docNav.CreateNavigator
        nav.MoveToRoot()
        nav.MoveToNext()
        Do
            Dim i As Integer
            i = +1
        Loop While nav.MoveToNext
        'Pause.
        Console.ReadLine()
        End Sub

Edited 3 Years Ago by chdboy

The first thing I see, declaring i in the do/while loop resets the value of i, each time the loop iterates. Also Console doesn't normally work in a form.

When you say navigate you'll have to be more specific. Your code doesn't really do anything. Do you want to be able to move back and forth through the nodes? Do you want to find specific nodes? What do you want to display, the whole node, the inner text, the name, etc.? What kind of control will you be using to display the information?

Edited 3 Years Ago by tinstaafl

I have 10 Fields in my table which I have displayed in the textboxes for row 1 ,I want to just display next set of rows inside the textboxes from the tables.and then navigate recodes backwards and forward by the click of a button. XML_problem

The code you're using to display is displaying all the rows, one after the other in the textboxes.

Something like this should work:

Public Class Form1
    Dim xmlFile As XmlReader
    Dim ds As New DataSet
    Dim DataBoxes as List(Of TextBox) = New List(Of TextBox)
    Dim Indx as Integer = 0
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For Each tb As TextBox In Me.Controls.OfType(Of TextBox)()
            If tb.Name.Contains("TextBox") Then
                DataBoxes.Add(tb)
            End If
        Next
        DataBoxes.Sort(AddressOf SortByNames)
        xmlFile = XmlReader.Create("Testimage.xml", New XmlReaderSettings())
        ds.ReadXml(xmlFile)
        Display(0)
    End Sub

    Private Sub Display(RowIndex As Integer)
        For I = 0 to DataBoxes.Count-1
            DataBoxes(I).Text = ds.Tables(0).Rows(RowIndex).Item(I+1)
        Next
    End Sub

    Private Function SortByNames(ByVal x As TextBox, ByVal y As TextBox) As Integer    
        Return x.Name.CompareTo(y.Name)
    End Function

    Private Sub ButtonForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonForward.Click
        Indx += 1
        If Indx > ds.Tables(0).Rows.Count-1 Then
            Indx = 0
        End If
        Display(Indx)
    End Sub

    Private Sub ButtonBackward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBackward.Click
        Indx -= 1
        If Indx < 0 Then
            Indx = ds.Tables(0).Rows.Count-1
        End If
        Display(Indx)
    End Sub 
End Class   

Edited 3 Years Ago by tinstaafl

When I click on the forward button or the back button nothing happens
here is the code for

 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Indx -= 1
        If Indx < 0 Then
            Indx = ds.Tables(0).Rows.Count - 1
        End If
        Display(Indx)
    End Sub

Forward code

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Indx += 1
        If Indx > ds.Tables(0).Rows.Count - 1 Then
            Indx = 0
        End If
        Display(Indx)
        End Sub

The data gets loaded each time the form loads perfectly,but clicking on forward and backward button nothing happens,no errors.

Can you upload a sample of the .xml file? I'll try and run it and see what's happening.

Edited 3 Years Ago by tinstaafl

as for now I'm not using XML files in my program any more so thread solved

This question has already been answered. Start a new discussion instead.