Add code to datasets in n-tier applications

 

You can extend the functionality of a dataset by creating a partial class file for the dataset and adding code to it (instead of adding code to the DatasetName.Dataset.Designer file). Partial classes enable code for a specific class to be divided among multiple physical files. For more information, see Partial or Partial Classes and Methods.

The code that defines a dataset is generated every time changes are made to the dataset definition (in the Creating and Editing Typed Datasets). This code is also generated when you make changes during the running of any wizard that modifies the configuration of a dataset. To prevent your code from being deleted during the regeneration of a dataset, add code to the dataset's partial class file.

By default, after you separate the dataset and TableAdapter code, the result is a discrete class file in each project. The original project has a filenamed DatasetName.Designer.vb (or DatasetName.Designer.cs) that contains the TableAdapter code. The project that's designated in the Dataset Project property has a file that's named DatasetName.DataSet.Designer.vb (or DatasetName.DataSet.Designer.cs).This file contains the dataset code.

System_CAPS_ICON_note.jpg Note

When you separate datasets and TableAdapters (by setting the DataSet Project property), existing partial dataset classes in the project won't be moved automatically. Existing dataset partial classes must be moved manually to the dataset project.

System_CAPS_ICON_note.jpg Note

When validation code needs to be added, the Creating and Editing Typed Datasetsprovides functionality for generating ColumnChanging and RowChanging event handlers. For more information, see Add validation to an n-tier dataset.

To add code to datasets in n-tier applications

  1. Locate the project that contains the .xsd file (the Creating and Editing Typed Datasets).

  2. Select the .xsd file to open the Creating and Editing Typed Datasets.

  3. Right-click the data table to which you want to add code (the table name in the title bar), and thenselectView Code.

    A partial class is created and opens in the Code Editor.

  4. Add code inside the partial class declaration.

    The following example shows where to add code to the CustomersDataTable in the NorthwindDataSet:

    partial class CustomersDataTable  
    {  
        // Add code here to add functionality  
        // to the CustomersDataTable.  
    }  
    
    

N-Tier Data Applications Overview
Add code to TableAdapters in n-tier applications
TableAdapters
TableAdapterManager Overview
Hierarchical Update Overview
Creating Data Applications
Dataset tools in Visual Studio

Show: