Adding the Functionality

Team-Fly team-fly    

 
ADO.NET Programming in Visual Basic .NET
By Steve  Holzner, Bob  Howell

Table of Contents
Chapter 11.   Creating Your Own Data Control


Before we begin coding, it would be a good idea to review the functionality of a data navigator control. Since we are incorporating the functionality of the ADO Data Control, we will review that as well. Even if you never used any of the data controls from previous versions of VB, you should still review this information because it will act as our functional specification.

A Data Navigator

Strictly speaking, a data navigator is a relatively simple idea. It should provide the user with the ability of moving through a collection of rows in a table. The First button moves to the beginning of the data rows. The Previous button moves one record backward. The Next button moves one record forward. The Last button moves to the last row in the collection. Although it would normally be used for database records, it could be used for arrays or any other collection of data. The control would need to be able to be bound to a data table or collection of some type and would also need to be able to be bound to a set of controls on the form. Our data navigator will provide all of this functionality and much more.

The VB 6 ADO Data Control

The ADO Data Control is more than a simple navigation control. It can act as a stand-alone visual control that would handle all of the details of connecting to, accessing, and updating database tables. Although you could (and I usually did) create your RecordSets outside the control and then assign the control's RecordSet property a reference to the externally created RecordSet, you didn't have to. The control would do it all for you with no code whatsoever. This is also the goal of our navigation control. It will contain all of the ADO .NET objects required to connect, access, and update the database with almost no code in the host form at all. It will also provide the mechanism through which the controls on the host form can be bound to the control. In addition to providing insight into the ADO .NET components , it will give a great deal of insight into the object-oriented capabilities of VB .NET.

VB 6Differences

Although our new control will mimic many of the functions of the VB 6 control, there will be some differences. The VB 6 control would automatically update the database with a connected RecordSet as soon as the user moved off the current row to another row. Since ADO .NET DataSets are disconnected, this will not happen. The DataRow in the DataTable will be updated, but the database will not. A separate method needs to be implemented to take care of updating the database with changes. We will create an UpdateChanges method for this purpose. The VB 6 control could manage at most one table. The ADO .NET DataSet can manage multiple tables. Since our control is best suited to managing one table at a time, we will create the BoundTable property. This will get or set an index value that determines which DataSet table we will be binding to. It will default to zero. In addition we need to provide for a DataAdapter. We will give our control the ability to create its own DataAdapter or be provided one already created by the programmer. As the VB 6 control exposed its RecordSet, we will also expose the DataSet. This way the user will have maximum flexibility to create a DataSet externally, and then supply it to the control. If this sounds ambitious, it is, but it will demonstrate the flexibility of ADO .NET.


Team-Fly team-fly    
Top


ADO. NET Programming in Visual Basic. NET
ADO.NET Programming in Visual Basic .NET (2nd Edition)
ISBN: 0131018817
EAN: 2147483647
Year: 2005
Pages: 123

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net