Creating and configuring datasets

Creating and configuring datasets in Visual Studio

 

A dataset is a set of objects that store data from a database in memory and support change tracking to enable CRUD operations on that data without the need to be always connected to the database. Datasets were designed for simple forms over data business applications. New applications should consider using Entity Framework to store and model data in memory. To work with datasets you should have a basic knowledge of database concepts.

You create a typed DataSet in Visual Studio at design-time by using the Data Source Configuration Wizard. For information on creating datasets programmatically, see Creating a DataSet.

  1. On the Project menu, click Add New Data Source to start the Data Source Configuration Wizard.

  2. Choose the type of data source you will be connecting to.

    Data Source Configuration Wizard
  3. For databases, choose the database or databases that will be the data source for your dataset.

    Data source choose a connection
  4. Choose the tables (or individual columns), stored procedures, functions and views from the database that you want to be represented in the dataset.

    Choose database objects
  5. Click Finish.

  6. The dataset appears as a node in Solution Explorer:

    DataSet in Solution Explorer

    Click on that node and the dataset appears in the DataSet Designer. Note that each table in the dataset has an associated TableAdapter which is represented at the bottom. The table adapter is used to populate the dataset and optionally to send commands to the database.

    DataSet Designer
  7. The relation lines that connect the tables represent table relationships as defined in the database. By default, foreign-key constraints in a database are represented as a relation only, with the update and delete rules set to none. Typically, that is what you want. However, you can click on the lines to bring up the Relation dialog, which enables you to change the behavior of hierarchical updates. For more information, see Relationships in datasets and Hierarchical Update

    Dataset Relation dialog
  8. Click on a table, table adapter, or column name in a table to see its properties in the Properties Window. You can modify some of the values here. Just remember you are modifying the dataset, not the source database.

    DataSet column properties
  9. You can add new tables or table adapters to the dataset, or add new queries for existing table adapters, or specify new relations between tables by dragging those items from the DataSet Toolbox tab, which appears when the DataSet Designer is in focus.

    Dataset Toolbox
  10. Next, you probably want to specify how to populate the Dataset with data. For that, you use the TableAdapter Configuration Wizard. For more information, see Filling datasets by using TableAdapters .

This procedure shows how to add a table from the same database that you used to first create the dataset.

  1. Click on the dataset node in Solution Explorer to bring the dataset designer into focus.

  2. Click on the Data Sources tab in the left margin of Visual Studio, or enter Data Sources in QuickLaunch.

  3. Right-click on the dataset node and choose "Configure data source with wizard...".

    Data Source context menu
  4. Use the wizard to specify which additional tables, or stored procedures or other database object to add to the dataset.

  1. Open your dataset in the Dataset Designer.

  2. Drag a DataTable from the DataSet tab of the Toolbox onto the Dataset Designer.

  3. Add columns to define your data table. For more information, see How to: Add Columns to a DataTable.

  4. Standalone tables need to have Fill logic implemented in order to be filled with data. For information on filling standalone data tables, see Populating a DataSet from a DataAdapter.

Show:
© 2016 Microsoft