This documentation is archived and is not being maintained.

Performing Database Operations Directly

Visual Studio .NET 2003

In many situations, you will design your data access strategy around using a dataset (an in-memory cache of data) and data adapters to fill the dataset and perform updates. In other situations, however, you might find it useful to bypass datasets and communicate directly with the data source. These situations include:

  • Performing queries on data intended to be read-only in your application. This might include executing a command that performs a database lookup.
  • Designing data access in ASP.NET Web applications, which under various circumstances might not benefit from using a dataset.
  • Executing a query that returns only a single value, such as a calculation or the result of an aggregate function.
  • Creating and modifying database structures, such as tables and stored procedures.

When you are creating tables and stored procedures or otherwise executing logic that does not return a result set, you cannot use a dataset; instead, you execute data commands directly. In the other situations, using data commands is an alternative to using data adapters and a dataset, and you can choose between the alternating ways to access data.

The following topics provide information on what data commands are and when and how to use them.

In This Section

Introduction to DataCommand Objects in Visual Studio
Provides an overview of data command objects and how to work with them.
Recommendations for Data Access Strategies
Provides information on choosing between datasets and data commands for data access.
Working with Data Commands: High-Level Process
Explains, at a high level, the steps involved in creating data commands and executing them.
Adding Data Commands to a Form or Component
Explains how to add a data command object to a form or component in Visual Studio.
Setting and Getting Data Command Parameters
Explains how to use the Parameters collection to pass data to commands and read return values after the command has been executed.
Executing a Data Command that Returns a Result Set
Provides instructions on how to execute a data command using a data reader that returns one or more records.
Executing Updates or Database Commands using a Data Command
Describes how to execute Update, Insert, and Delete statements directly against the database, and how to issue database definition language (DDL) commands.
Executing a Data Command that Returns a Single Value
Provides instructions on how to execute a command that returns a single value, such as a command that performs a lookup or calculates a value.

Related Topics

Web Data Access Strategy Recommendations
Provides guidelines for choosing whether to use direct access to a data source or a disconnected cache (dataset); and if you use a dataset, whether to store it between round trips.
Introduction to Datasets
Provides an overview of datasets and how they are used to cache data.
Introduction to Dataset Updates
Provides information on how data updates are made using datasets and data adapters.
Connecting to Data Sources with ADO.NET
Provides links to topics about creating and working with connection objects in Visual Studio.
Concurrency Control in ADO.NET
Provides information on how to work with concurrency control in ADO.NET.
Executing a Command
Provides information from the .NET Framework Developer's Guide about using data commands programmatically.
Retrieving Data Using the DataReader
Provides information from the .NET Framework Developer's Guide on using the data reader to work with the results of a command programmatically, including how to work with the results of multiple statements or procedures.
Obtaining Data as XML from SQL Server
Provides information from the .NET Framework Developer's Guide on how to get data in XML format from a SQL Server 7.0 or later database using a data command and an XMLReader object.
Modifying Data in a Database
Provides information from the .NET Framework Developer's Guide about executing update commands against a database.
Performing Catalog Operations
Provides more code examples of how to execute database definition (DDL) commands.
Obtaining a Single Value from a Database
Provides information from the .NET Framework Developer's Guide on executing commands that return a scalar value.
Introduction to Data Access with ADO.NET
Explains the ADO.NET data model and provides an architectural diagram that shows where data commands fit in.
Adding a Launch Condition for Microsoft Data Access Components
Describes how to check that the correct version of the ADO.NET data access components is available when you install your application.