Designer Support


Although ADO.NET provides a great deal of power in a small amount of code, you still may prefer not to do all the hand coding required in the earlier examples. For that reason, VS.NET provides integrated data access directly in the Windows Forms designer. In the Toolbox window there is a Data Tab, as shown in Figure 12.5.

Figure 12.5. Data Toolbox

This Toolbox contains the various kinds of data access objects you'll commonly need. These objects are instances of components , so they don't have UIs of their own. When they're added to a design surface, they cluster along the bottom just like any other component.

Connection Objects

A connection object exists to establish the connection to the data provider, and this means that you're primarily concerned with the ConnectionString property. If you're overly eager , you can type this in manually. More commonly, you'll let the Property Browser provide you access to the Data Link Properties dialog, as shown in Figure 12.6.

Figure 12.6. Data Link Properties Dialog

Command Objects

As with connections, dropping a command object does not immediately add any assistance to creating a connection, but again, the Property Browser does, as shown in Figure 12.7.

Figure 12.7. Command Properties

When setting the Connection property, you'll get a drop-down list of all the known connections on the form. After you select one, you can set the CommandText property using Query Builder, as shown in Figure 12.8.

Figure 12.8. Query Builder

When the CommandType property is set to Text, Query Builder will help you specify the type of query your command will need to generate. You can add tables, views, and functions from your database and customize the query by using the Designer as necessary. If CommandType is set to Stored Procedure or to TableDirect, you're on your own with the CommandText.

Data Adapter Objects

The data adapter continues to build on the connection objects as well as the command objects. When you drag a data adapter object onto your form, the Designer starts a Data Adapter Configuration Wizard to create a data adapter, which will include a connection object and one or more command objects. The Data Adapter Configuration Wizard can create any missing objects, saving you those steps. The wizard walks you through very specific steps:

  1. You specify and create a connection.

  2. You create one or more commands for the data adapter, including the select, insert, update, and delete commands.

  3. You create the data adapter to tie all the objects together.

When you're finished with this wizard, the generated code creates the connection, the command objects, and the data adapter, associating objects with each other as needed.



Windows Forms Programming in C#
Windows Forms Programming in C#
ISBN: 0321116208
EAN: 2147483647
Year: 2003
Pages: 136
Authors: Chris Sells

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