|
|
 |
| General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums. If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category.
** PLEASE BE SPECIFIC WITH YOUR QUESTION **
When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the General .NET section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

January 26th, 2005, 02:48 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Object Reference is Not Set to an Instance of an O
Dear all,
I am trying to write and better my skills coding some small junk of codes.
With the example codes from MSDN I have managed to write the below code in order to edit some selected node from an xml file.
But the below code gives me an error unexpectedly. :(
It says Object Reference is Not Set to an Instance of an Object at the line highlighted below.
I think root or id returns null.
can anyone help me about this.
Code:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
'Try
'Send updates to xml file
Dim xDoc As XmlDocument = New XmlDocument()
Dim root As XmlNode = xDoc.DocumentElement
Dim id As XmlNode
Dim i As Integer
'root = xDoc.DocumentElement
For i = 0 To root.ChildNodes.Count - 1
id = root.ChildNodes(i).Attributes("CustomerID")
If (id.InnerText = txtUniqueID.Text) Then
xDoc.DocumentElement("CustomerID").Value = txtUniqueID.Text
xDoc.DocumentElement("CompanyName").Value = txtCoName.Text
xDoc.DocumentElement("ContactName").Value = txtContact.Text
xDoc.DocumentElement("ContactTitle").Value = txtTitle.Text
xDoc.DocumentElement("Address1").Value = txtAddress.Text
xDoc.DocumentElement("Phone1").Value = txtPhone1.Text
xDoc.DocumentElement("Phone2").Value = txtPhone2.Text
xDoc.DocumentElement("reason").Value = txtservice.Text
End If
Next i
xDoc.Save(m_connCustomers)
'Reset and begin again
LoadDataSet()
MsgBox("Record has been updated.")
'Attempt to update the datasource.
Me.LoadDataSet()
'Catch eUpdate As System.Exception
' 'Add your error handling code here.
' 'Display error message, if any.
' System.Windows.Forms.MessageBox.Show(eUpdate.Message)
'End Try
Me.dsCust_PositionChanged()
End Sub
Best,
|

January 27th, 2005, 02:34 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You havent loaded the XML Document in the function.
|

February 1st, 2005, 03:52 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how can i do it?
can you point me an example?
best,
|

February 1st, 2005, 05:01 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dim xDoc As XmlDocument = New XmlDocument()
xDoc.Load("XmlFileName")
|

February 1st, 2005, 05:42 AM
|
|
Registered User
|
|
Join Date: Jan 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks a million.
best,
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |