Examples: Data Binding
- Apr 01, 2018
#Examples
- How to: Bind GridControl to Database and Implement Master-Detail Mode at Design Time
- How to: Bind a GridControl to a Database in Server Mode
- How to: Bind a Control to a Database at Runtime
- How to: Bind a Control to Data Created at Runtime
- How to: Add an Unbound Column Storing Arbitrary Data
- How to: Filter a LookUp(ComboBox) Column Based on Another Column Value
- How to: Reload Data from the Bound Database in Server Mode (XPO)
- How to: Create and Customize a GridLookUpEdit Control at Runtime
- How to: Create and customize a custom GridLookUpEdit control
#Knowledge Base Articles
- How to filter the second LookUp column based on the first LookUp column's value
- Can I use the Grid Control in unbound mode?
- How to Make Sure That All Modifications Are Saved
- What is the best way to refresh the on-screen data if the datasource is an ArrayList?
- Can the grid display data from several data tables in a single Grid View?
- How to display a self-referenced data table via master and detail Grid Views
- How to synchronize a data bound control with a detail Grid View
- How to clear the grid
SEE ALSO
How to: Bind a Control to a Database at Runtime
This example demonstrates how to bind a data-aware control (XtraGrid, XtraPivotGrid, XtraVerticalGrid, etc.) to a database at runtime. Note that specific controls may need additional customization after the control is bound to a data source. For more information, refer to documentation of the corresponding control.
The following code demonstrates a way of binding a GridControl to the Products table of the NWind database.
using System.Data.OleDb;
// ...
// Create a connection object.
OleDbConnection connection = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\DBs\\NWIND.MDB");
// Create a data adapter.
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Products", connection);
// Create and fill a dataset.
DataSet sourceDataSet = new DataSet();
adapter.Fill(sourceDataSet);
// Specify the data source for the grid control.
gridControl1.DataSource = sourceDataSet.Tables[0];