473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Datagrid.databind error when dataset XML contains attributes...

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!
Nov 18 '05 #1
2 1669
Ringo,

Are you sure this is true:
dsResults.Tables("grp").Columns.Contains("Name") returns true, so I know it's in there.

Based on the XML you provided below, that should return false.

Your data is nested so much that the below XML (assuming this was the whole
file) would create the following tables:

record
grp
Address
CityStateZip
Name

The grp table only contains grp_Id, display, and record_Id.

If you take the "display" attribute out of your Name element it will pull
the Name into the grp table instead of creating a separate Name table.

Travis Murray
MCSD, MCT
Artiem Consulting, Inc
http://www.artiem.com

"ringo" <rgp@ringosoft*NoSpam*.com> wrote in message
news:pn***********************@twister.southeast.r r.com... 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!

Nov 18 '05 #2
Thanks for your response.

Travis Murray wrote:
Ringo,

Are you sure this is true:

dsResults.Tables("grp").Columns.Contains("Name ") returns true, so I know
it's in there.

Based on the XML you provided below, that should return false.


I'm positive this is true; I just tried it again. Since sometimes certain fields
are not included with the XML, part of the error checking code I snipped out is:

If dsResults.Tables("grp").Columns.Contains("Name") = False Then
dsResults.Tables("grp").Columns.Add("Name")
End If

which would then allow the XML to bind to the grid without the <Name> element
being present (and just be blank in the grid). Since it returns True, the Column
is not added to the dataset, and the error is thrown.
Your data is nested so much that the below XML (assuming this was the whole
file) would create the following tables:

record
grp
Address
CityStateZip
Name

The grp table only contains grp_Id, display, and record_Id.

If you take the "display" attribute out of your Name element it will pull
the Name into the grp table instead of creating a separate Name table.

Since I can't control the format of the XML coming in, how could I bind the
data I need to the grid?

Travis Murray
MCSD, MCT
Artiem Consulting, Inc
http://www.artiem.com

"ringo" <rgp@ringosoft*NoSpam*.com> wrote in message
news:pn***********************@twister.southeast.r r.com...
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!


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff Thur | last post by:
I am getting this error when trying to run a stored procedure: Microsoft.VisualBasic.CompilerServices.LateBinding.LateInd exGet(Object o, Object args, String paramnames) +1361...
2
by: nss | last post by:
hi, I created web page ( .aspx) then i imported datagrid on that page with dataset. But when i launch the page on web server the datagrid is invisiable. Can someone help me how i can make it...
4
by: Sanjay | last post by:
I have written a web service to return information from the database. This works and the data is returned in XML format from the database and displayed on the web page as well when this web service...
2
by: Mesut KoÅŸucu | last post by:
hi all i get a error when update user attributes the error is "General access denied error " the code is Dim strAttrName As String = Me.TextBox1.Text Dim strAttrValue As String =...
4
by: Dee | last post by:
Hi, I'm working on a sample WebForm proj that accesses an Access database. There is a desgn-time DataSet ds1 and a DataGrid dg. Page_Load contains 2 lines: da.Fill(ds1) dg.DataBind().
0
by: Karim | last post by:
I have a datagrid with a collection of columns and the datagrid is populated as in the code below. The value of test = 3 rows which is correct. However I get an exception when the code hits the...
2
by: david | last post by:
Problem: There is a search button, Search, in form, for searching patient info list. The error occurs after the following steps: 1. search first time is OK, and all found the records are...
2
by: Andrew | last post by:
hi, I got an error when the dataset returns a null value. eg. string a; a = (string)ds.Tables.Rows; How do I handle this error ? Thanks. regards,
1
by: Alex Maghen | last post by:
I have a DataGrid on my ASPX and I'm confused about the interaction with the page based on whether the page is just loading or is being reloaded with a call to the SortCommand of the DataGrid: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.