Monthly Archives: May 2015

How to load an Access Database into a DataSet object in C#

Today I needed to load a Microsoft Access Database (*.ACCDB / *.MDB) into a DataSet  object in .NET environment using C#.

After finding some (partial) solutions I finally developed a little C# class in order to accomplish this task. This class loads an Access Database (whatever in ACCDB or MDB formats) into a DataSet  object. After the operation you can directly access to the loaded tables by using the .Tables  property of the generated DataSet object.

To use it, it’s really simple:

  1. Add the provided AccessDbLoader  class to your project.
  2. Load the Access Database file by using the following snippet:
    DataSet ds = AccessDbLoader.LoadFromFile("my.accdb");
  3. You can now use the ds.Tables  property.

For your convenience you’ll find a sample program below:

I think this class can be improved in some ways (e.g. handling primary / foreign keys constraints) but that’s enough for my needs.