Add code to TableAdapters in n-tier applications

 

For the latest documentation on Visual Studio 2017, see Add code to TableAdapters in n-tier applications on docs.microsoft.com. You can extend the functionality of a TableAdapter by creating a partial class file for the TableAdapter 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 (Type).

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

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 file named 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 named DatasetName.DataSet.Designer.vb (or DatasetName.DataSet.Designer.cs) that 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 will not be moved automatically. Existing dataset partial classes must be moved manually to the dataset project.

System_CAPS_ICON_note.jpg Note

The Creating and Editing Typed Datasets provides functionality for generating ColumnChanging and RowChanging event handlers when validation is needed. For more information, see Add validation to an n-tier dataset.

System_CAPS_ICON_note.jpg Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Personalizing the IDE.

To add user code to a TableAdapter in an n-tier application

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

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

  3. Right-click the TableAdapter that you want to add code to, and then selectView Code.

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

  4. Add code inside the partial class declaration.

  5. The following example shows where to add code to the CustomersTableAdapter in the NorthwindDataSet:

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

N-Tier Data Applications Overview
Add code to datasets in n-tier applications
TableAdapters
TableAdapterManager Overview
Hierarchical Update Overview
Creating Data Applications

Show: