XML File as Data Source and Bind To DataSet in vb.net

What we would want to do is define a data layer class, keep an instance of the DataSet, and provide methods and properties to access the DataSet. I haven’t been able to use these concept at GE Healthcare yet but will be soon hopefully. Hope this helps somebody.

Sample usage would be:

Private m_dataLayer As New DataLayer(Application.StartupPath & "\Data.xml")

Me.DataGridView1.DataSource = m_dataLayer.Tables("Employee")

Imports System.Data
 
Public Class DataLayer
 
   Private m_data As DataSet
   Private m_fileName As String
 
   Public Sub New(ByVal fileName As String)
      m_data = new DataSet()
      m_data.ReadXml(fileName)
      m_fileName = fileName
   End Sub
 
   Public ReadOnly Property Table(ByVal tableName As String)
     Get
       Return m_data.Tables(tableName)
     End Get
   End Property
 
   Public Sub Write()
      m_data.WriteXml(m_fileName)
   End Sub
 
End Class
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: