5
Reply

Unable to read from XML file

Anjan Kumar

Anjan Kumar

May 1 2014 5:31 AM
911
 
Iam writing a code to read XML file and display it in DataGridView, but it doesn't work, my code is as follows...
give me suggestions
 
DataTable an = new DataTable();
XmlDocument xmldoc=new XmlDocument();
FileStream fsazm = new FileStream("D:\\data.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
xmldoc.Load(fsazm);
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Student");
for (int i = 0; i < xmlnode.Count; i++)
{
XmlAttributeCollection xattrc = xmlnode[i].Attributes;
an.Rows[i][0] = xattrc[0].Value;
an.Rows[i][1] = xattrc[1].Value;
}

Answers (5)