Access

Access, developed by Microsoft, one of Office applications, is a relational database management system (RDBMS).

Access offers seven things to build objects of database system. They are table, query, form, report, page, macro and template. Also, in order to standardize operation to save, query data, design interface and generate report, it provides users with various guides, builders and templates. Access is very convenient and easy to use because users don’t need to write code to manage data.

Access can save and get materials in Access/Jet, Microsoft SQL Server, Oracle and any ODBC compatible database. Therefore, the proficient programmers often use it to develop helpful applications.

Export Data to Access

Access has several advantages. One is easy to save and convenient for managing. Therefore, sometimes, people may export data to Access.

Next, I will talk something about how to export data to Access with C#.  

This method is based on a component, Spire.DataExport. So, we need to download and install it firstly.

Then, we need to create a Windows Form project and create a form. In the form, add a group box to show datasource which includes connection string and command text. Then, add a datagridview and add AccessExport included in Spire.DataExport. Finally, add button to run.

Now, double click Run and write code.

private void btnMSAccess_Click(object sender, EventArgs e)

{

    System.Data.OleDb.OleDbConnection oleDbConnection1

         = new System.Data.OleDb.OleDbConnection();

    oleDbConnection1.ConnectionString

        = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\Database\demo.mdb";

 

    System.Data.OleDb.OleDbCommand oleDbCommand1

        = new System.Data.OleDb.OleDbCommand();

    oleDbCommand1.CommandText = "select * from parts";

    oleDbCommand1.Connection = oleDbConnection1;

 

    Spire.DataExport.Access.AccessExport accessExport1

        = new Spire.DataExport.Access.AccessExport();

 

    accessExport1.DatabaseName = "test.mdb";

    accessExport1.DataFormats.CultureName = "zh-CN";

    accessExport1.DataFormats.Currency = "c";

    accessExport1.DataFormats.DateTime = "yyyy-M-d H:mm";

    accessExport1.DataFormats.Float = "g";

    accessExport1.DataFormats.Integer = "g";

    accessExport1.DataFormats.Time = "H:mm";

    accessExport1.SQLCommand = oleDbCommand1;

    accessExport1.TableName = "ExportData";

 

    oleDbConnection1.Open();

    accessExport1.SaveToFile();

}

After running, we can get data in Access file.