Home > DeveloperSection > Forums > how to fetch xml data in datagridview?
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    January-06-2016 10:17 PM

 C# C#  .NET  XML  XML Reader 
Ratings:


 1 Reply(s)
 348  View(s)
Rate this:
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?


Anupam Mishra

Total Post:135

Points:949
Posted on    January-06-2016 10:51 PM

Suppose your XML file contents are:

<?xml version="1.0" encoding="utf-8" ?>
<EMPLOYEES>
  <EMP>
    <EMPNO>
001</EMPNO>
    <ENAME>Anupam Mishra</ENAME>
    <JOB>Software Developer</JOB>
    <MGR>0XX008</MGR>
    <HIREDATE>01-SEP-92</HIREDATE>
    <SAL>80000</SAL>
    </EMP>
    <EMP>
    <EMPNO>
010</EMPNO>
    <ENAME>Vibhav Mahto</ENAME>
    <JOB>Sr. Software Developer</JOB>
    <MGR>0XX0001</MGR>
    <HIREDATE>01-JAN-90</HIREDATE>
    <SAL>8000</SAL>
    </EMP>

   </EMPLOYEES>

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:









Modified On Jan-06-2016 10:54:39 PM

Don't want to miss updates? Please click the below button!

Follow MindStick