Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
In my form I have 2 text boxes, combobox and save my data in form with XML.
My code:
C#
 private void Bok_Click(object sender, EventArgs e)
        {
            engcmd.Engname = TBname.Text;
            engcmd.EngDescription = TBDescription.Text;
            engcmd.EngCommand = CBCommmand.Items[CBCommmand.SelectedIndex].Text;

           
            XmlElement enginecommand = doc.CreateElement("enginecommand");
            doc.AppendChild(enginecommand);

            XmlElement nameengc = doc.CreateElement("nameengc");
            XmlElement desengc = doc.CreateElement("desengc");
            XmlElement commandengc = doc.CreateElement("commandengc");
            XmlAttribute stageid = doc.CreateAttribute("stageid");

            XmlText nameengctext = doc.CreateTextNode(TBname.Text);
            XmlText desengctext = doc.CreateTextNode(TBDescription.Text);
            XmlText commandengctext = doc.CreateTextNode(CBCommmand.Items[CBCommmand.SelectedIndex].Text);

            enginecommand.Attributes.Append(stageid);
            enginecommand.AppendChild(nameengc);
            enginecommand.AppendChild(desengc);
            enginecommand.AppendChild(commandengc);

            nameengc.AppendChild(nameengctext);
            desengc.AppendChild(desengctext);
            commandengc.AppendChild(commandengctext);

            doc.Save(Application.StartupPath + "/TestProcedureEdit.xml");

            this.Close();
        }
private void Fillcontrol()
        {
            XmlNode node = doc.DocumentElement;

            TBname.Text = node.ChildNodes[0].InnerText;
            TBDescription.Text = node.ChildNodes[1].InnerText;
            CBCommmand.Items[CBCommmand.SelectedIndex].Text = node.ChildNodes[3].InnerText;
        }

But there is an error.

please help me.
Posted
Updated 16-Nov-11 0:06am
v2
Comments
RaisKazi 16-Nov-11 6:06am    
What is Error?
msh66 16-Nov-11 11:15am    
error:
Object reference not set to an instance of an object.
Sergey Alexandrovich Kryukov 16-Nov-11 12:33pm    
What are you trying to achieve?
--SA
fjdiewornncalwe 16-Nov-11 13:16pm    
If you have an Object reference error, then it should be quite simple to place a breakpoint at the top of the method throwing the error and then use F10 to step through each line until you encounter the object that is not initialized. Take care of this and you move on to your next error.

1 solution

you are mising out object from any one of these lines of code, debug using putting breakpiont and share us about the code..

C#
enginecommand.Attributes.Append(stageid);
enginecommand.AppendChild(nameengc);
enginecommand.AppendChild(desengc);
enginecommand.AppendChild(commandengc);
nameengc.AppendChild(nameengctext);
desengc.AppendChild(desengctext);
commandengc.AppendChild(commandengctext);


thanks
 
Share this answer
 
v2
Comments
msh66 22-Nov-11 6:53am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900