Creating XML Schemas and Datasets from Existing Data
The XML Designer allows you to easily create schemas and datasets based on any table, stored procedure, or view that can be browsed in the data connection area of Server Explorer. Additionally, you can pick and choose individual columns if the entire data structure is not needed.
You create a schema based on existing data sources when the existing source contains the desired structure for your application. This is a quick way to build up your schema without having to define each individual element.
Schemas and datasets can also be created programmatically from any data source that you have access to at run time.
To create a schema to match an existing data source
- In Solution Explorer, right-click the project you want to add the dataset to, select Add, and then select Add New Item.
- In the Add New Item dialog box, select Dataset, give the dataset a name, and then click Open.
A new, blank schema file (.xsd) and a corresponding Dataset class file are added to your project.Note The name you use will also be the name of the Dataset class file generated from the schema.
- In Server Explorer, expand the Data Connections node and then expand the node for the connection to the data source you want to use.
Note If you do not already have a connection, create one. For more information, see Adding New Data Connections in Server Explorer.
- In the Connection node, expand the node for Tables, Stored Procedures, or Views, depending on what you want to infer the schema structure from.
- If you want to build the schema based on only specific columns (not on all columns in the data source), open the source node and select the columns you want.
- Drag the selected table, view, stored procedure, or columns onto the XML Designer.
- Save the schema.
Visual Studio creates the schema structure from the elements you specify and regenerates the corresponding class file for your typed dataset.
- If you have added multiple tables to the dataset and want to establish a relationship between them, add a DataRelation object to the schema. For more information, see Creating DataRelation Objects with the XML Designer.
If you need to make changes to the schema, you can use the XML Designer to add, edit, and remove elements.
Creating XML Schemas and Datasets | Creating XML Schemas from XML Files | Relationship Between XML Schemas and Datasets | Relational Data in XML Schemas | XML Files | XML Schemas and Data | Introduction to Data Access with ADO.NET | Introduction to Datasets