New to Telerik UI for WinForms? Download free 30-day trial

Tutorial: Binding to MS Access DataTable/Database

The following tutorial demonstrates binding to a single database table. For information on binding to multiple tables see the Binding to Hierarchical Data topic.

WinForms RadGridView Binding to MS Access DataTable/Database

This tutorial is applicable for Visual Studio 2019 (or prior versions). If you're using Visual Studio to connect to Access databases, you will need to be aware that versions of Visual Studio prior to Visual Studio 2022 are all 32-bit processes. This means some of the data tools in Visual Studio 2019 and earlier will only be able to connect to Access databases using 32-bit data providers. The last version of Visual Studio that was a 32-bit process was Visual Studio 2019. READ MORE

1. Place a RadGridView component on a form. Set the Dock property to Fill.

2. In the Properties window locate the DataSource property and click the arrow to open the list. Select the Add Project Data Source... link. This step will display the Data Source Configuration Wizard.

WinForms RadGridView Data Source Configuration Wizard

3. In the Data Source Configuration Wizard Choose a Data Source Type page, select the Database icon. Click the Next button.

WinForms RadGridView DataSource Type

4. In the Choose Your data Connection page click the New Connection... button. This step will display the Add Connection dialog.WinForms RadGridView New Connection

5. In the Add Connection dialog click the Change... button. This step will display the Change Data Source dialog.

WinForms RadGridView Change Data Source dialog

6. Select the Microsoft Access Database File data source. Click the OK button to close the Change Data Source dialog.

WinForms RadGridView Microsoft Access Database File

7. The Add Connection dialog will appear. Click the Database File Name Browse button and locate the "NWind.mdb" file from the Telerik UI for WinForms directory in the "\Examples\DataSources" directory. Click the OK button to close the Add Connection dialog.

8. In the Choose Your Database Objects page, select the "Categories" table. Click the Finish button to close the Data Source Configuration Wizard.

WinForms RadGridView Categories Table

9. In the Visual Studio Properties window for the grid DataSource property select the "Categories" table. This step will create DataSet, BindingSource and TableAdapter objects for the categories table.

WinForms RadGridView DataSet

10. The project design should look something like the screenshot below. Note the new data components in the component tray under the design surface.

WinForms RadGridView Data Components

11. Replace the Form_Load event handler with the following code. The "foreach" code iterates all the columns in the grid and calls BestFit() so that the columns will expand to show the data.

private void TutorialBindingToDataTableOrDataSet_Load(object sender, EventArgs e)
{
    this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
    foreach (GridViewDataColumn column in radGridView1.Columns)
    {
        column.BestFit();
    }
}

Private Sub TutorialBindingToDataTableOrDataSet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.CategoriesTableAdapter.Fill(Me.NwindDataSet.Categories)
    For Each column As GridViewDataColumn In RadGridView1.Columns
        column.BestFit()
    Next
End Sub

12. Press F5 to run the application.

See Also

In this article