Skip to main content

Tutorial: Bind the Grid to ADO.NET Data

  • 2 minutes to read

In this tutorial, you will learn how to do the following:

  • Create and configure an ADO.NET data source in a WinForms project.
  • Bind the DevExpress WinForms Data Grid to a data source.
  • Post changes to the database.

Watch Video: Bind Grid to SQL Database

Create an ADO.NET Data Source

  1. Invoke the grid control’s smart tag menu and open the Data Source Configuration Wizard.

    Open data source wizard in WinForms grid smart tag menu

  2. Choose “ADO.NET Typed DataSet” and click New Data Source.

    Create new ADO.NET data source in WinForms Data Source Configuration Wizard

  3. Select the Database source type and click Next.

    Select data source type in WinForms Data Source Configuration Wizard

  4. Choose Dataset and click Next.

    Select database model type in WinForms Data Source Configuration Wizard

  5. Choose an existing data connection or create and configure a new connection. This tutorial uses an existing connection to a local SQL Northwind database.

    Choose data connection in WinForms Data Source Configuration Wizard

  6. Specify the connection string name and click Next.

    Save connection to application configuration file in WinForms Data Source Configuration Wizard

  7. Select required tables and data fields in the database and click Finish.

    Select database objects in WinForms Data Source Configuration Wizard

Bind the Grid to the ADO.NET Data Source

In the grid control’s smart tag menu, open the drop-down menu next to the Choose Data Source option and select a table.

Set data source in WinForms Grid smart tag menu

The following auto-generated code loads data into nwindDataSet:

void Form1_Load(object sender, EventArgs e) {
    this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
}

Post Data to the Database

The following code snippet handles the Form’s FormClosing event and calls the table adapter’s Update method to post changes to the database:

private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
    categoriesTableAdapter.Adapter.Update(nwindDataSet);
}

Tip

Read the following help topic for additional information: Post Data to an Underlying Data Source.

See Also