Avatar of ZekeLA
ZekeLA
Flag for United States of America asked on

Can't load Dataset with XML and Schema from another Dataset

I'm trying to pass a dataset as xml from my web service to my web page. My example code is below and gives me a "Root element is missing" error.

Here's my code behind:
' This is actually a web service method
Public Function GetDatasetXml(ByRef sXmlSchema As String) As String
    Dim sSQL As String = "SELECT ProductId, Name, Color FROM Product WHERE Color IS NULL"
    Dim ds As New Dataset = DbHelper.OpenDataset(sSQL)

     sXmlSchema = ds.GetXmlSchema()

     return ds.GetXml()
End Function

Public Sub BindMarkup
    Dim sXMLSchema As String = String.Empty
    Dim sXML As String = GetDatasetXml(sXMLSchema)

    Dim readerXMLSchema As XmlReader = XmlReader.Create(New StringReader(sXMLSchema))
    Dim readerXML As New System.IO.StringReader(sXML)

    Dim ds As New DataSet
    ds.ReadXmlSchema(readerXML)
    ds.ReadXml(readerXML, XmlReadMode.ReadSchema)

    Me.rptList.DataSource = ds
    Me.rptList.DataBind()
End Sub

Open in new window

and my markup:
      <asp:Repeater ID="rptList" runat="server" >
        <ItemTemplate>
             <%# DataBinder.Eval(Container.DataItem, "ProductID")%><br>
             &nbsp;&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "Name")%><br>
             &nbsp;&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "Color")%><br>
        </ItemTemplate>
      </asp:Repeater>

Open in new window


I tried this originally without using the XML Schema but that failed because the Color field is null and caused the repeater to complain the Color field wasn't found. So I know I need the schema but I can't figure out how to get this to work.

Thanks in advance.
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
ZekeLA

8/22/2022 - Mon
ZekeLA

ASKER
A developer friend of mine gave me the solution. I'll post it if it's not proprietary.
ASKER CERTIFIED SOLUTION
ZekeLA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61