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

R

ringo

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top