how to fetch xml data in datagridview?

I am importing data from an xml file to my datagridview in c# .The problem is that only one row is shown in data grid view .Please give me a suitable example to fetch all records from datagridview?
Last updated:1/6/2016 10:51:28 PM

1 Answers

Anupam Mishra
Anupam Mishra

Suppose your XML file contents are:

<?xml version='1.0' encoding='utf-8' ?>
    <ENAME>Anupam Mishra</ENAME>
    <JOB>Software Developer</JOB>
    <ENAME>Vibhav Mahto</ENAME>
    <JOB>Sr. Software Developer</JOB>
For displaying all rows to xml file.As you say, you are using datagridview.  The suitable code is shown below from fecthing data to any xml file :
   DataSet dataSet = new DataSet();
   dataSet.ReadXml(@'D:\Anupam Mishra\06.01.2016\UsingLinqEx\UsingLin\LinqEx.xml');
   dataGridView1.DataSource = dataSet.Tables[0];
You can also used a foreach or for loop of large iteration items for fetching values of any xml file.
Output of this program is follows: