The .NET Platform
Development Tools
COM & COM+
Data Access
Web Development
XML Technologies
Windows Servers
Wireless & Mobile
Security issues
Design & Process
Career Development
Analysis & Comment
Disposable Objects
You are not logged in: login here to access all areas.
Visual Studio 2005 includes full support for both ADO.NET 2.0 and System.Xml 2.0, with many new features for working with both relational and XML data. Alex Homer explains.
Author: Alex Homer
Last updated: May 2005
Visual Studio has always provided wide-ranging support for database and relational data access, and Visual Studio 2005 is no exception with great tools for connecting to databases, viewing and editing the data, linking data to controls, and writing code that manipulates relational data. Shown below is the Server Explorer with connections to two databases. Also shown is the Data menu which allows you to manipulate the database by adding new tables, stored procedures, and so forth. The Server Explorer window and the Data menu functions The DataSet Designer The Data Sources window and a typed DataSet for the Northwind Customers table Previewing the data returned from the typed DataSet Enhanced Support for XML Editing an XML document with conformance checking and validation enabled Visual Studio 2005 supports both XML Schemas (XSD files) and Document Type Definitions (DTD files). It can also convert Microsoft XML Data Reduced (XDR) schema file to the now-standard XSD type. There is also a graphical schema designer that you can use to create new schemas, and a built-in feature available from the XML menu that can infer a schema from an existing XML document. SQL Server 2005 Project Support Creating a new SQL Server Project and selecting the template When you build the solution, Visual Studio automatically publishes it to the database, registering it if necessary, and creates test scripts so you can check that it behaves as expected.
Visual Studio 2005 comes with an updated DataSet Designer which makes it easy to create strongly-typed DataSet instances to store and manipulate your data. A typed DataSet essentially consists of a custom class that wraps a standard ADO.NET DataSet and exposes the rows and column values as strongly typed properties. It can also expose methods and events that can be used to work with the data contained within the DataSet.
In the Data Sources window you simply click the Add Data Source icon to run the Data Source Configuration Wizard. Here you select the options to connect to the required data source; specify the data required; and Visual Studio creates the typed DataSet for you. The result is shown below, together with the Preview Data dialog that you can open from the Data menu afterwards. You will find the call to the GetData method that the Wizard creates within the 1,300 or so lines of auto-generated code that makes up the typed DataSet class.
Developers are increasingly working with XML data in their applications, and Visual Studio 2005 provides a range of new or enhanced features that XML developers will find useful. You can create and edit XML documents, XML schemas and XSLT style sheets in the editor, which provides syntax and conformance checking and validation automatically.
Validation is performed through a schema that is attached to the current document, and Visual Studio 2005 provides a schema repository pre-loaded with most of the commonly-used schemas for XML, XSLT, HTML, XHTML and so forth. You can also add your own schemas to the repository. The repository makes it easy to attach one or more schemas to a loaded XML document, and the editor will then help you to create and modify the document.
For example, shown below is an XML document being edited. This document has a schema attached, and so errors in the document are displayed in the editor. The opening element tag <slide-title> violates the form of the document, and the tags that are affected are underlined in red. The value of the last position attribute ("four") violates the schema rule that this should be a numeric value, and so it is underlined in blue as it is a validation error. You can also see the IntelliSense feature that helps you create documents that comply with the schema by listing only the elements that are valid at the current insertion point. 
SQL Server 2005 supports user-defined types (UDTs). These are custom classes that implement a data storage object, and they can be stored in a column in an SQL Server 2005 table. ADO.NET contains methods to interact with and manipulate UDTs within a DataReader and a DataSet. However, the assembly that implements the UDT must be compiled and stored in SQL Server before they can be used.
It's also possible to take advantage of the new hosted Common Language Runtime feature offered by SQL Server 2005 to write code that implements stored procedures or aggregates within the database. All of these features are supported by Visual Studio 2005, though the new SQL Server 2005 Project.
When you start a new project, you can select a SQL Server Project from the Database section of the New Project dialog. Once you have specified the database to connect to, you can then select from a range of available templates that help you create a stored procedure, trigger, aggregate or user-defined type (see below).
Click here for our Privacy Statement. Copyright © Matt Publishing. All rights reserved. No part of this site may be reproduced without the prior consent of the copyright holder.