Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2005, 02:48 AM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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,

 
Old January 27th, 2005, 02:34 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

You havent loaded the XML Document in the function.

 
Old February 1st, 2005, 03:52 AM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how can i do it?

can you point me an example?

best,

 
Old February 1st, 2005, 05:01 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default


Dim xDoc As XmlDocument = New XmlDocument()
xDoc.Load("XmlFileName")

 
Old February 1st, 2005, 05:42 AM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a million.
best,






Similar Threads
Thread Thread Starter Forum Replies Last Post
Object reference not set to an instance of an obje rturner003 ASP.NET 2.0 Professional 0 December 26th, 2006 08:30 PM
Object reference not set to an instance of an obj nrathod_97 BOOK: Beginning VB.NET Databases 4 June 21st, 2005 06:35 PM
Object reference not set to an instance of an obje williadn General .NET 0 January 18th, 2005 05:39 PM
Object reference not set to an instance... steelman BOOK: ASP.NET Website Programming Problem-Design-Solution 6 May 7th, 2004 02:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.