dataset.Databind error when dataset XML contains attributes...

Discussion in 'ASP .Net Datagrid Control' started by ringo, Aug 18, 2004.

  1. ringo

    ringo Guest

    I've come accross an interesting problem populating an asp.net datagrid. I am trying to bind
    XML data to a datagrid as I've done in countless other applications, the only difference this
    time being that the XML I'm getting has attributes within the elements which I need to bind
    to the grid. Example XML (I need to populate the datagrid with the address, name, and
    CityStateZip elements):

    <properties>
    <record display="properties" no="1">
    <grp display="">
    <Address display="Street Address">906 MAIN ST</Address>
    <CityStateZip display="Address 2">RALEIGH, NC 55555</CityStateZip>
    <Name display="Name">SMITH JOHN E</Name>
    </grp>
    </record>
    </properties>

    My code is as follows (strXML is a string containing the XML above, dgProperty
    is the datagrid):

    Dim rdrXML As System.IO.StringReader
    Dim dsResults As New DataSet()

    rdrXML = New System.IO.StringReader(strXML)
    dsResults.ReadXml(rdrXML)

    dgProperty.DataSource = dsResults.Tables("grp")
    dgProperty.DataBind()

    On the last statement, the application throws the error:

    A field or property with the name 'Name' was not found on the selected datasource.

    dsResults.Tables("grp").Columns.Contains("Name") returns true, so I know it's in there.
    Furthermore, if I remove the 'display' attributes from the elements to be bound, as in:

    <properties>
    <record display="properties" no="1">
    <grp display="">
    <Address>906 MAIN ST</Address>
    <CityStateZip>RALEIGH, NC 55555</CityStateZip>
    <Name>SMITH JOHN E</Name>
    </grp>
    </record>
    </properties>

    everything works just fine. After many hours of searching for an answer I'm at the
    end of my rope. Any suggestions are much appreciated!
     
    ringo, Aug 18, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Dyer
    Replies:
    5
    Views:
    665
  2. ringo
    Replies:
    2
    Views:
    693
    ringo
    Aug 18, 2004
  3. Replies:
    0
    Views:
    442
  4. Replies:
    3
    Views:
    2,954
  5. Michael
    Replies:
    0
    Views:
    233
    Michael
    Dec 29, 2003
Loading...

Share This Page