In Brief

This chapter gave us our start in database handling. Here's an overview of this chapter's topics:

  • ADO.NET is the main data access protocol in C#. ADO.NET centers on three primary objectsconnection objects, which let you connect to data sources; data adapter objects, which store SQL statements and are responsible for fetching and storing data; and dataset objects, which hold a copy of your data locally. ADO.NET uses a disconnected data architecture, where no connection to the data source is maintained . Connections are made when you need to get more data or update the data in the data source.

  • The IDE comes with several visual tools that let you work with databases. For example, the Server Explorer lets you examine not only which database providers you can connect to, but which data connections you've made, and we've seen how to create data connections as well. To create data adapters and connection objects, you simply have to drag a data adapter from the toolbox onto a form.

  • Simple-bound controls display data from a single field in a record, such as text boxes, check boxes, labels, and buttons . To bind these controls at design time, you can use the DataBindings property, which displays a few commonly-bound properties for each control such as the Text property for text boxes and labels.

  • You can data-bind every property of simple-bound controls if you select the Advanced property in the DataBindings property entry. The data type of the property you're binding must be the same as the data field you're binding to.

  • Complex-bound controls display data from multiple fields at once. Complex binding centers on four properties: DataSource (the data source), DataMember (the member you want to work with in a data source, usually a database table), DisplayMember (the field whose data you want the control to display), and ValueMember (the field whose data the control will return in properties like SelectedValue ).

  • You can navigate through a dataset and have bound controls update automatically as you do so in Windows forms. You use the form's BindingContext property, which returns a collection of BindingManagerBase objects, and you can use these objects to set the current record for all controls in the form. Specifically, you use the Position property of a BindingManagerBase object to set the current record, and the Count property to determine the total number of records.

  • SQL parameters work much like variables in SQL statements. You can assign values to SQL parameters at runtime without having to change the SQL in a data adapter. All you have to do is to assign a new value to a SQL parameter in a data adapter and use that data adapter to fill a data container like a dataset.

Microsoft Visual C#. NET 2003 Kick Start
Microsoft Visual C#.NET 2003 Kick Start
ISBN: 0672325470
EAN: 2147483647
Year: 2002
Pages: 181

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: