alt
Advertisement
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow VB.NET 2005 arrow .NET Complex Data Binding
Site Search


.NET Complex Data Binding
Article Index
.NET Complex Data Binding
Page 2

.

.

.

One-Way and Two-Way Data Binding

All that we have done, so far, is to ensure that the data in a database is retrieved and displayed to us using any of the Forms Controls. It is clear that some controls can take user input while others are prevented from taking user input. It is also evident that some controls provide dynamic views while others display only static views based on a snapshot of data.

This brings us to the next concept that needs to be understood. Binding allows data update depending on the type of control used. Bindings that do not allow the user to update the database that provided the user with the data are called One-Way Binding and the type of binding that allows the user to update the underlying database are called Two-Way Binding.

Two way bindings are available in all cases where the data source can be updated and the control has the capacity to display updated data. The user, however, has the option to prevent this by editing the properties of the control.

Closely allied to the concept of two way binding is the concept of System.DataSet. This concept was introduced in Visual Basic.NET to present a XML schema that is aware of the rowstate property. The rowstate property gets or sets the value of the rows so as to track changes to the row.

The System.Data.Common.DataAdapter’s Update method examines the System.Data.DataRow.RowState property, and executes the required INSERT, UPDATE, or DELETE statements iteratively for each row, based on the order of the indexes configured in the System.Data.DataSet. For example, System.Data.Common.DataAdapter.Update might execute a DELETE statement, followed by an INSERT statement, and then another DELETE statement, due to the ordering of the rows in the System.Data.DataTable. Let us see the code fragment for this

Click here for Sample Code

It should be noted that these statements are not executed as a batch process; each row is updated individually. This could raise some exceptions which the users will have to handle separately.

The BindingContext and CurrencyManager Classes

Binding controls on a form to the ADO.NET DataSet and providing navigation services that keep all controls in sync is accomplished through the use of two objects known as the CurrencyManager and the BindingContext. For each data-bound form that the user creates in the application, the user will have at least one BindingContext object. This object will be responsible for any CurrencyManager objects. The user will have one CurrencyManager object for each data source on the user’s form. The CurrencyManager object is responsible for keeping track of the user’s position in the DataSet and for the overall supervision of the bindings to the data source. The user will call the necessary methods on the CurrencyManager object to navigate through the records, and the BindingContext ensures that all bound controls are kept in sync. The DataNavigator control used in this application provides that functionality in an easier-to-use form.

The use of binding context can be illustrated by the following example where three text boxes are bound to three columns of the same table. While navigating, the synchronization of the three columns is made possible by BindingContext.


Trackback(0)
Comments (0)add comment

Write comment

busy

 
< Prev   Next >
Sponsored Links
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape