Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

XML To Dataset

Hi-

I have a sql SP that returns XML

SELECT TOP 10
       [Title]
      ,[FirstName]
      ,[MiddleName]
      ,[LastName]
      ,[Suffix]
      ,[CompanyName]    
  FROM [AdventureWorksLT2008].[SalesLT].[Customer]
ORDER BY
   [FirstName], [LastName]
FOR XML AUTO, ROOT('customer')

I need to get this into datatable but the code below does not seen to work!

   Dim sqlConnection1 As New SqlConnection("Data Source=XXX; Database=AdventureWorksLT2008; User ID=XXX;Password=XXX;")
        Dim cmd As New SqlCommand
        Dim adapter As New SqlDataAdapter
        Dim ds As New DataSet("customer")
        cmd.CommandText = "SimpleSelectXML"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection = sqlConnection1
        Try
            sqlConnection1.Open()
            Dim xr As XmlReader = cmd.ExecuteXmlReader()
            ds.ReadXml(xr.Read)
            cmd.Dispose()
            gv1.DataSource = ds
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            sqlConnection1.Close()
        End Try

Help would be appreciated!

Thanks in advance
0
doctor069
Asked:
doctor069
1 Solution
 
informaniacCommented:
Does changing

ds.ReadXml(xr.Read)

to

ds.ReadXml(xr)

help?
0
 
doctor069Author Commented:
Yes!
Thank you very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now