Data Binding

From Wildsong
Jump to navigationJump to search

Data Binding with C#

Binding is used to create a two-way connection between a data object and a Windows control.

One-way means that the data can be displayed in the control. Example: a list of elements living in a SQL table can be used to populate a list control.

Two-way means that the control can be used to update the data. Example: a SQL table can populate a DataGridView table and when a cell in the table is changed the SQL table can be updated.

DataSet a DataTable collection, with relations and constraints. Relations can be created with DataRelation objects.

DataTablea data container that represents a table; it contains DataRow and DataColumn collections.

DataView a DataTable container with some additional properties available including Filter and Sort.

DataAdapter is a container for the SQL commands and database connection that us used to fill a DataSet.

So... for a "simple" example,

  • You create a DataSet
  • You create a DataAdapter and specify the table you want to use with a bit of SQL
  • A DataTable to contain the table will be added to the DataSet
  • If you connect the DataTable to a control via its DataSource property, you can see the table contents.