Error when Reading from XML file

Iron

New Member
i have an XML file like this\[code\] <?xml version="1.0" encoding="utf-8" ?> <conStr> <server>192.168.1.25;</server> <initial_catalog>chargdb;</initial_catalog> <uid>sa;</uid> <pwd>1;</pwd> </conStr>\[/code\]and i'm using this code for fetch data from this file :\[code\] XmlDocument xd = new XmlDocument(); xd.Load(Application.StartupPath + @"\cng.xml"); string conStr = string.Empty; conStr += "server="; conStr +=xd.DocumentElement.ChildNodes[0].Attributes["server"].Value; conStr += "initial catalog="; conStr += xd.DocumentElement.ChildNodes[0].Attributes["initial_catalog"].Value; conStr += "uid="; conStr += xd.DocumentElement.ChildNodes[0].Attributes["uid"].Value; conStr += "pwd="; conStr += xd.DocumentElement.ChildNodes[0].Attributes["pwd"].Value; MessageBox.Show(conStr);\[/code\]but each time i give an error message like this: "Object reference not set to an instance of an object." please help me, what can i do to read my file? thanks
 
Back
Top