|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
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
Open the dataset in the Dataset Designer. For more information, see How to: Open a Dataset in the Dataset Designer.
Double-click the design surface in an empty area to open the dataset's partial class file in the code editor.
Add your code to the dataset's partial class file.
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.