---
title: "how to fetch xml data in datagridview?"  
description: "how to fetch xml data in datagridview?"  
author: "Manoj Bhatt"  
published: 2016-01-06  
updated: 2016-01-06  
canonical: https://www.mindstick.com/forum/33842/how-to-fetch-xml-data-in-datagridview  
category: "c#"  
tags: ["c#", ".net", "xml", "xml reader"]  
reading_time: 1 minute  

---

# how to fetch xml data in datagridview?

I am importing data from an [xml file](https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php) to my [datagridview in c#](https://www.mindstick.com/forum/523/set-button-name-in-datagridview-in-c-sharp) .The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is that only one row is shown in [data grid](https://www.mindstick.com/forum/105/what-events-fire-when-binding-data-to-a-data-grid) [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) .Please give me a suitable example to [fetch](https://www.mindstick.com/forum/156159/what-is-google-fetch) all [records](https://www.mindstick.com/forum/34640/how-to-create-a-stored-procedure-for-display-all-records) from datagridview?

## Replies

### Reply by Anupam Mishra

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](https://www.mindstick.com/articles/607/working-with-datagridview-in-vc-sharp). The suitable code is shown below from fecthing [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) 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:\
\
![how to fetch xml data in datagridview?](https://www.mindstick.com/mindstickforums/df5c10c9-51ab-4785-9e5d-6630e2390ae8/images/7dd43a1d-87f4-42a4-a853-1be6e99d062d.png)\
\
\
\
\
\
\


---

Original Source: https://www.mindstick.com/forum/33842/how-to-fetch-xml-data-in-datagridview

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
