471,337 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Combo XML problems

am trying to have XML data show results in a combobox (Which works) and
when the combobox has a selection, change the text in a label field.

I am following the video from
http://msdn.microsoft.com/vbasic/att...l/default.aspx (reading
XML data) almost step by step (changing to match my xmlfiles, etc)

Here is an example of my XML
<product>CP-90, T-32</product>
<address>Street Address</address>

My load function (which works)

Dim xmlFile As String = "..\Products.xml"
Dim xmlDoc As XmlDocument
Private Sub Zadig_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim xmlTr As New XmlTextReader(xmlFile)

While xmlTr.Read
If xmlTr.Name = "product" AndAlso xmlTr.NodeType =
XmlNodeType.Element Then
End If
End While

xmlDoc = New XmlDocument

End Sub

My selection method
Private Sub cmbProducts_SelectionChangeCommitted(ByVal sender As Object,
ByVal e As System.EventArgs) Handles cmbProducts.SelectionChangeCommitted
DisplayProduct(cmbProducts.SelectedIndex + 1)
End Sub

Here is where the problem begins

Sub DisplayProduct(ByVal position As Integer)
Dim node As XmlNode = xmlDoc.SelectSingleNode( _
"/products/product[" & position & "]")
lblCompany.Text = node.SelectSingleNode("company").InnerText

End Sub

Everything compiles fine but when I run and then select a product I get.
An unhandled exception of type 'System.NullReferenceException' occurred in

Additional information: Object reference not set to an instance of an object.

The error says it is on line "lblCompany.Text =
node.SelectSingleNode("company").InnerText" but I have no idea what the real
problem is.

Please advise.


Jul 21 '05 #1
0 837

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by meganrobertson22 | last post: by
2 posts views Thread by Jason Huang | last post: by
6 posts views Thread by vb | last post: by
9 posts views Thread by Duncan Barnes-Ceeney | last post: by
7 posts views Thread by Ausclad | last post: by

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.