Creating Data Adapters Using Server Explorer
This procedure describes creating data adapters from Server Explorer. Often, you will want to make configuration changes to the adapter after creating it. For details, see Creating and Configuring Data Adapters Manually.
To create a data adapter with Server Explorer
- Open the form or component in the appropriate designer and then open Server Explorer. For details, see Accessing and Initializing Server Explorer.
- If the connection you need does not already exist, create it. For details, see Adding New Data Connections in Server Explorer.
Security 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 Database Security.
- Open the connection node and then expand any of the element nodes (Tables, Stored Procedures, Views, or Functions). If you are working with tables, expand the table name node to display the table columns.
Note If you are working with stored procedures, you will need to manually configure the UpdateCommand, InsertCommand, and DeleteCommand properties of the adapter after creating it. For details, see Creating and Configuring Data Adapters Manually.
- Select one or more columns (under Table) or a stored procedure, and then drag the selection onto the designer.
Note You can drag the table name to the designer instead of selecting and dragging individual columns. Doing so results in an SQL SELECT * FROM tablename query. Selecting individual columns is generally more efficient, because you limit the amount of data that is transferred between the database and the dataset.
When you drop the selection onto the designer, Visual Studio creates an instance of a connection object for that data source (if there is not already one there) and a data adapter object.
If you dragged a table or individual columns onto the designer, the adapter is configured for both reading and updating data. If you dragged a stored procedure onto the designer, the adapter is configured for reading data. For details about configuring the commands for updating, see Creating and Configuring Data Adapters Manually.
- If you want to see how the data adapter will fill a dataset, preview the results. For details, see Previewing Data-Adapter Results.
At this point, you can create a dataset based on information in the adapter. For details, see Creating Typed Datasets with the Component Designer.
Dragging data elements from Server Explorer is easy, but does not give you the opportunity to create a parameterized query or to create new stored procedures to access data. For that, you can use the Data Adapter Configuration Wizard. For details, see Creating Data Adapters Using a Wizard.