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.
Create an ADO.NET Data Source
Invoke the grid control’s smart tag menu and open the Data Source Configuration Wizard.
Choose “ADO.NET Typed DataSet” and click New Data Source.
Select the Database source type and click Next.
Choose Dataset and click Next.
Choose an existing data connection or create and configure a new connection. This tutorial uses an existing connection to a local SQL Northwind database.
Specify the connection string name and click Next.
Select required tables and data fields in the database and click Finish.
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.
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.