Partager via


How to: Extend the Functionality of a Dataset

You can extend the functionality of typed datasets by writing code into the dataset's partial class file.

The code that defines typed datasets is regenerated when changes are made in the Dataset Designer or when changes are made during the running of any of the wizards that create or modify objects in the dataset; for example, the Data Source Configuration Wizard, and the TableAdapter wizards. To prevent your code from being deleted during regeneration of the dataset, add code to the dataset's partial class file. (Partial classes allow code for a specific class to be divided among multiple physical files. For more information, see Partial (Visual Basic) or partial (Type) (C# Reference).)

To create the dataset's partial class file and add validation code, double-click columns and tables, which result in the generation of ColumnChanging and RowChanging event handlers. For more information, see How to: Validate Data During Column Changes and How to: Validate Data During Row Changes.

To add code to a typed dataset's partial class file

  1. Open the dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.

  2. Double-click the design surface in an empty area to open the dataset's partial class file in the code editor.

  3. Add your code to the dataset's partial class file.

    Note

    The code in the partial class file and the generated dataset class file is compiled into one class, so variable, property, and method names, and so on must be unique across all files that define the dataset, or compiler errors will occur.

See Also

Reference

Partial (Visual Basic)

Partial Classes and Methods (C# Programming Guide)

Concepts

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Overview of Data Applications in Visual Studio

Connecting to Data in Visual Studio

Tools for Working with Data Sources in Visual Studio