How to Display the Records in the DataGridView Using VB.Net and XML File

In this tutorial, I will teach you how to display the record in the datagridview using vb.net and xml file. This simple project will help you how to get the records from XML file and display it into the DataGridView. It also illustrates what is the method to be used when they bind to each other. Hope this tutorial will help your current problem. Let’s begin.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form. ps1

Step 2

Add a Button and DataGridView in the form. It will look like this. ps2

Step 3

Go to the solution explorer and right-click the project name. After that, select “Add” and hit “new itemps3

Step 4

Choose XML File in the dialog box, then hit “add”. ps4

Step 5

Double click the XML file and add the following codes for the list of records.
  1.  
  2. <NewDataSet>
  3.   <person>
  4.     <Name>Janno Palacios</Name>
  5.     <Address>Kabankalan City</Address>
  6.   </person>
  7.   <person>
  8.     <Name>Jeanniebe Palacios</Name>
  9.     <Address>Kabankalan City</Address>
  10.   </person>
  11.   <person>
  12.     <Name>Craig Palacios</Name>
  13.     <Address>Kabankalan City</Address>
  14.   </person>
  15.   <person>
  16.     <Name>Kenjie Palacios</Name>
  17.     <Address>Kabankalan City</Address>
  18.   </person>
  19. </NewDataSet>

Step 6

Go to the resources and drag the XML file. ps5

Step 7

Double click the button and do the following codes for retrieving data in the XML File when the button is click.
  1.  
  2.      Dim dsPerson As DataSet = New DataSet()
  3.         dsPerson.ReadXml(New System.IO.StringReader(My.Resources.XMLFile1))
  4.         DataGridView1.DataSource = dsPerson.Tables(0)
The complete source code is included. You can download it and run it on your computer. For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Add new comment