p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > .NET > Other .NET > General .NET
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 26th, 2005, 02:48 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: , , .
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,

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old January 27th, 2005, 02:34 PM
Friend of Wrox
Points: 657, Level: 9
Points: 657, Level: 9 Points: 657, Level: 9 Points: 657, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old February 1st, 2005, 03:52 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how can i do it?

can you point me an example?

best,

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old February 1st, 2005, 05:01 AM
Friend of Wrox
Points: 657, Level: 9
Points: 657, Level: 9 Points: 657, Level: 9 Points: 657, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
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")

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old February 1st, 2005, 05:42 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a million.
best,

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 07: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 03:03 AM
Object reference not set to an instance of an obje aashishpatil ASP.NET 1.1 1 October 8th, 2003 10:17 AM



All times are GMT -4. The time now is 08:14 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc