Connecting to MS Access 2013

Setting up the MS Access 2013 Connection

  1. Before you begin, make sure you either have MS Access installed on your computer, or download and install the drivers for MS Access.
    Here is an example of both x64 and x86 drivers (found at: Control Panel > System and Security > Administrative Tools > ODBC Data Sources (x86/x84)):




    Once you have verified that you have the drivers you are ready to begin.

  2. Start by adding System.Data.Odbc to your list of using statements.
    Next, create a new OdbcConnection object and pass in your Connection string, then open the connection as follows. Substitute your own parameters within the brackets.

    32 bit: OdbcConnection myConnection = new OdbcConnection("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=[DataBase mbd file location];");
    64 bit: OdbcConnection myConnection = new OdbcConnection("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=[DataBase mbd/accdb file location];");

    myConnection.Open();




  3. You should now have an open connection to MS Access.

Filling a Table Using OdbcDataAdapter

  1. Start by creating a new OdbcCommand object and passing in Select statment.

    i.e. OdbcCommand cmd = new OdbcCommand("Select * From MyTable;");

  2. Next, set the cmd.Connection to your OdbcConnection.

    i.e. cmd.Connection = myConnection;

  3. Create your OdbcDataAdapter and pass in your newly made cmd object.

    i.e. OdbcDataAdapter oda = new OdbcDataAdapter(cmd);

  4. Finally, you will populate your datatable. Call the OdbcDataAdapter's Fill() method and pass in the table you wish to populate.
    This is the call that will actually execute your Select command.

    i.e. oda.Fill(myDataTable);



  5. Your datatable should now be popluated.