Data Binding

From Wildsong
Revision as of 17:43, 2 February 2008 by Brian Wilson (talk | contribs) (New page: 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. ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 DataTable
  • You create a DataSet and add the DataTable to it
  • You create a DataAdapter and specify the table you want to use with a bit of SQL
  • You connect the actual table to the DataTable by connecting the DataAdapter to the DataSet
  • If you connect the DataTable to a control via its DataSource property, you can see the table contents.