- // Contact.xml
- <?xml version="1.0" encoding="utf-8" ?>
- <contacts>
- <contact>
- <firstname>John</firstname>
- <lastname>Smith</lastname>
- <email>john.smith@xyzmail.com</email>
- </contact>
- <contact>
- <firstname>Suzan</firstname>
- <lastname>Carter</lastname>
- <email>suzan.carter@xyzmail.com</email>
- </contact>
- <contact>
- <firstname>Tom</firstname>
- <lastname>Baker</lastname>
- <email>tom.baker@xyzmail.com</email>
- </contact>
- </contacts>
- Imports System.Data
- Public Class Form1
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim ContactsSet As New DataSet("Contacts")
- ContactsSet.ReadXml("Contact.xml")
- DataGridView1.DataSource = ContactsSet
- DataGridView1.DataMember = "Contact"
- End Sub
- End Class
VB.Net - XML To DataGridView
This code snippet shows how to load data from an XML file into a DataGridView control using the DataSet class.
No comments:
Post a Comment