0

There are many examples of reading an xml file and populating a datagridview. I would like to pull the xml from a string instead.

        Dim myXMLfile As String = "C:\tmp\accountlist.xml"
        Dim ds As New DataSet()
        ds.ReadXml(myXMLfile)
        DataGrid1.DataSource = ds
        DataGrid1.DataMember = "account"

The above code works when the xml data is read from a file. I cannot figure out how to read the xml from a string and get it to work.

        Dim myxml as string
        myxml = "<response><item><acct>1001</acct></item><item><acct>1002</acct></item></response>"
2
Contributors
1
Reply
5
Views
3 Years
Discussion Span
Last Post by cgeier
0

Try this:

        Dim myxml As String
        myxml = "<response><item><acct>1001</acct></item><item><acct>1002</acct></item></response>"

        Dim ds As New DataSet()

        ds.ReadXml(New System.IO.StringReader(myxml))

        Dim DataGridView1 As New DataGridView()

        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "item"

        Me.Controls.Add(DataGridView1)

Edited by cgeier

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.