How to: Create Data Adapters by Using a Wizard

.NET Framework 3.5

The Data Adapter Configuration Wizard provides the simplest and most flexible way to create data adapters. For details, see Data Adapter Configuration Wizard.

NoteNote:

In the previous version of Visual Studio, data adapters were used for communicating between an application and a database. While data adapters are still a main component of .NET Framework Data Providers (ADO.NET), TableAdapters are designer-generated components that simplify the process of moving data between your application and a database. For more information on working with TableAdapters, see TableAdapter Overview.

NoteNote:

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

By default in Visual Studio, design-time support for data adapters has been turned off. To this support for data adapters, you must add them to the Toolbox, as described in the first procedure below.

To add data adapters, connections, and commands to the Toolbox

  1. Right-click the Toolbox and choose Choose Items.

  2. Select the items you want to add from the .NET Framework Components tab of the Choose Toolbox Items dialog box. For example, to use the .NET Framework Data Provider for SQL Server select the SqlDataAdapter, SqlConnection, and SqlCommand.

  3. Click OK to add the selected items to the Toolbox.

To create a data adapter using the Data Adapter Configuration Wizard

  1. Open the form or component you are creating in the appropriate designer.

  2. From the Data tab of the Toolbox, drag an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object onto the design surface.

    The designer adds an instance of the adapter to the form or component and launches the Data Adapter Configuration Wizard.

  3. In the wizard, do the following:

    1. In the second page, create or choose a connection. For more information about creating connections, see Establishing the Connection (ADO.NET).

      Security noteSecurity Note:

      Storing connection-string details (such as the server name, user name, and password) can have implications for the security of your application. Using Windows Integrated Security is a more secure way to control access to a database. For more information, see Securing ADO.NET Applications.

    2. In the third page, specify whether the adapter should use SQL statements or stored procedures to read and write data. Choose one of the options listed in the following table.

      Option

      Description

      Use SQL statement

      You will define an SQL SELECT statement that the adapter will use to populate a table in the dataset. Based on your SELECT statement, the wizard will also generate UPDATE, INSERT, and DELETE statements for updating the data source.

      Use newly created stored procedures

      You specify a SELECT statement, and the wizard creates stored procedures from the statement to read and update the data source. If the provider does not support this option, it is grayed out.

      Use existing stored procedures

      You will specify existing stored procedures that the adapter will use to read and update the data source.

      The choice you make determines what appears on the following pane.

    3. In the fourth page, either create the SELECT statement or select the existing stored procedures. For assistance building the SQL statement, click SQL Builder to launch the Query Builder.

      NoteNote:

      You can create a query with a parameter placeholders in the WHERE clause, which will be filled with information you gather at run time. For details, see Parameters in Data-Adapter Commands.

    When you have finished the wizard, it generates an instance of a connection object with the information you specified in the second page.

  4. If you want to change the name of the adapter and connection, select them individually in the designer and give them each a new name in the Properties window.

  5. If you want to see what data the adapter will fill into the dataset, you can preview it. For details, see How to: Preview Data-Adapter Results.

You can also create and configure an adapter manually. To do so, you must already have a connection object available. Part of configuring the data adapter involves establishing table mappings between tables in the data source and the dataset. For details, see How to: Create and Configure Data Adapters Manually.

Community Additions

Show: