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>"

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.