Export (0) Print
Expand All

Data Form Wizard

Visual Studio .NET 2003

Helps you create Web Forms pages or Windows Forms with data-bound controls. The controls display data from any data source you specify.

Running the Wizard

Running Data Form Wizard is like adding an item to an existing project.

To run the Data Form Wizard

  1. Create or open a Windows Application or ASP.NET Web Application, depending on whether you want to use the wizard to create a Web Forms page or Windows Form.
    Note   The wizard can create a form only in a project type that supports forms.
  2. From the File menu, choose Add New Item.

    The Add New Item dialog box appears.

  3. In the Templates pane, select Data Form Wizard.

    The wizard starts.

  4. Follow the steps of the wizard.

What the Wizard Does

The Data Form Wizard runs you through the entire process of creating the data-bound form. When you have finished, you will have:

  • A Web Forms page or Windows Form.
  • Data-bound controls on the form.
  • All necessary data components for the form.
  • Methods that you can call to read and, for Windows Forms, write data.

The Form and Controls

To display data, the wizard-generated form includes controls that are bound to a data source. For example, the form can contain a grid control.

In a Windows Form, you can choose between a grid or individual controls that show one record at a time. In a Web Forms page, the control is always a grid. If you use individual controls in a Windows Form, you can also generate buttons that allow users to navigate between records.

Finally, in a Windows Form, you can include buttons to save changes to records and to add new records. This option is not available if you generate a Web Forms page; the page is read-only.

Data Elements

The Data Form Wizard can create new data components or use ones already available in your project. A data component for the form consists of several discrete elements:

  • A connection to a data source such as a database.
  • A data adapter that references a SQL statement or stored procedure to get data.
  • A typed dataset to hold the records fetched from the database. The dataset includes a schema, a dataset class file, and an instance of the dataset on the form.

If you use the wizard to create a data source, it assumes that you want to connect to a database. Within the database, the wizard can access tables or views.

The wizard can optionally create and use a reference to an XML Web service as the data source. In that scenario, the XML Web service is assumed to be able to return a dataset.

You can use the wizard to access multiple tables and establish relationships between them. In that case, the controls on the form allow you to view both parent and child records.

Fill and Update Methods

One of the tasks that needs to be performed in your form is to fill the dataset with data from the database. By default, to fill the dataset, the wizard generates a Load button that calls code to perform the fill operation. If you are creating a new dataset with the wizard, the wizard generates the Fill method automatically. If you are working with an existing dataset, the wizard offers you these options for creating a Fill method:

  • Select an existing method. If your project exposes a method that returns a dataset (either as the return value of a function or as a parameter), you can select that method and the wizard generates code to call that method. A common scenario is that you have a reference to an XML Web service in your project already and want to call a method of that XML Web service to fill that dataset.
  • Skip the method. Choose this option if you want to fill the dataset yourself rather than having the fill code be called automatically.

If you are generating a Windows Form, the wizard can also generate an Update method you can call to send changes from the dataset back to the data source. In Web Forms pages, the wizard does generate an Update button, but it does not create any update code. If you want the page to allow updates, you can add your own code to do that.

After Running the Data Form Wizard

When the wizard is finished and you have a new form, the form is ready to run. There are a few additional steps you might have to take, and a variety of ways in which you can expand on what the wizard has done.

Because the Data Form Wizard is designed to create output for a variety of combinations of forms (Windows Forms, Web Forms pages), controls, and data sources, the code generated by the wizard might not be the optimal code for any one specific situation. For more information about what code the wizard generates and what modifications you might want to make to it, see Data Form Wizard Generated Code.

Steps That Might Be Required

To work with the form you just created, you might need to do the following:

Additional Steps for Further Development

The wizard creates controls and data elements and all the code required to run the form. You can read and modify this code as necessary. (You cannot open a generated form using the wizard in order to edit it.)

You might want to perform the following to enhance the form created by the wizard.

  • Change the look and arrangement of controls on the form.
  • If the form has a Load button to fill the dataset, you can move the fill code somewhere else. A typical example is to move it from the button event handler to the form initialization method so that the dataset is filled automatically when the form runs.
  • In Web Forms pages, add logic to allow updates from the page. For more information, see Data Form Wizard Generated Code.
  • Refine the queries generated by the wizard for the data adapter to retrieve a subset of the data and to add or modify parameters to the adapter's commands. For more information see Configuring Parameters for Data Adapters.
  • Add validation or business logic to the form.

See Also

Data Form Wizard Generated Code | Creating Windows Forms | Web Forms Pages | Windows Forms Walkthroughs | Web Walkthroughs | Data Walkthroughs

Show:
© 2014 Microsoft