470,815 Members | 1,290 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Problem accessing complex XML child node when using Dataset

I'm having problems accessing a complex XML child node (latitude &
longitude), and passing it to a function when the XML file has been read
into a DataSet. Specifically, the returned object from accessing the
'latitude' and 'longitude' nodes is not a DataTable (as specified in the
MSDN). I'm not sure what type is being returned, nor how to go about
finding out. Any pointers would be appreciated. Below is the relevent
Error message, XML, and VB code. Thanks for your time and attention.

N. Demos
Error Msg:
Exception Details: System.InvalidCastException: Specified cast is not valid.
<state>Ivory Coast</state>
Public lstbxCities1 As ListBox
Public lblMon As Label

Public Sub Page_Load(Source As Object, E As EventArgs)
Dim dataSet As DataSet = LoadCityData()

If Not dataSet Is Nothing Then
Dim zRow As DataRow

For Each zRow In dataSet.Tables(0).Rows
Dim lstitmListItem As New ListItem()
lstitmListItem.text = zRow.Item("name") & ", " & zRow.Item("state")

'*** Problem Occurs Here ***
lstitmListItem.value = "latitude:" &
ToDegreeString(zRow.Item("latitude")) & _
"longitude:" & ToDegreeString(zRow.Item("longitude"))

lstbxCities1.Height = New Unit(20.0, UnitType.EM)
End If

End Sub

Function ToDegreeString(dtblCoords As DataTable) As String
Dim zRow As DataRow = dtblCoords.Rows(0)
Dim dTotDegrees As Double

Dim dDeg As Double = XmlConvert.ToDouble(zRow.Item("deg"))
Dim dMin As Double = XmlConvert.ToDouble(zRow.Item("min"))
Dim dSec As Double = XmlConvert.ToDouble(zRow.Item("sec"))

dTotDegrees = DMSToDegrees(dDeg, dMin, dSec)

Dim strOutput As String = XmlConvert.ToString(dTotDegrees) & "," &
zRow.Item("hemisphere") & ";"

Return strOutput
End Function
Change "seven" to a digit to email me.
Nov 19 '05 #1
0 1459

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tony Girgenti | last post: by
4 posts views Thread by SteveT | last post: by
2 posts views Thread by Richard Carpenter | last post: by
2 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.