This documentation is archived and is not being maintained.

Working with Data Commands: High-Level Process

Visual Studio .NET 2003

ADO.NET data commands give you the ability to execute commands directly against a database or other data source, without needing a dataset or data adapter. For more information, see Introduction to DataCommand Objects in Visual Studio.

Security Note   When using data commands with a CommandType property set to Text, carefully check information that is sent from a client before passing it to your database. Malicious users might try to send (inject) modified or additional SQL statements in an effort to gain unauthorized access or damage the database. Before you transfer user input to a database, you should always verify that the information is valid; best practice is to always use parameterized queries or stored procedures when possible.

To use a data command in Visual Studio, you perform a set of steps, some at design time and others at run time, typically using code.

To work with data commands

  1. At design time, add a data command to your form or component and set:
    • Its SQL command or stored procedure.
    • Any parameters that the command requires.

    For more information, see Adding Data Commands to a Form or Component.

    Note   As with all data components, you can also create and configure a data command programmatically at run time. For more information, see Executing a Command.
  2. At run time, set any parameter values that you want to pass to the data command. You often get parameter values from information that the user enters into a form or that is passed from another component. For more information, see Setting and Getting Data Command Parameters.
  3. Execute the command. This runs the SQL command or stored procedure associated with the command. The exact command you use to execute the data command depends on what you expect the command to return: a result set, a scalar value, a count of affected value, or XML data.
  4. Read the return value or values from the data command. As with executing the command, the way you read results vary depending on what type of command you executed and what it returns.

    For more information about different ways to execute commands and get their results, see the following topics:

See Also

Introduction to DataCommand Objects in Visual Studio | Retrieving Data Using the DataReader | Executing a Command | Obtaining Data as XML from SQL Server | Modifying Data in a Database | Performing Catalog Operations | Obtaining a Single Value from a Database