Results 1 to 2 of 2

Thread: How to navigate records from XML File?

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    119

    Question How to navigate records from XML File?

    This code creates XML File
    Code:
    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 reads the file and send it's contents to text box(es)

    Code:
     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 Navigates to the next record....and needs help
    Code:
     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
    Last edited by chdboy; Feb 26th, 2013 at 11:18 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width