O'Reilly logo

Visual Basic 2008 Recipes: A Problem-Solution Approach by Rakesh Rajan, Matthew MacDonald, Allen Jones, Todd Herman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.6. Use Parameters in a SQL Command or Stored Procedure

Problem

You need to set the arguments of a stored procedure or use parameters in a SQL query to improve flexibility.

Solution

Create parameter objects appropriate to the type of command object you intend to execute. Configure the parameter objects' data types, values, and directions and add them to the command object's parameter collection using the DbCommand.Parameters.Add method.

How It Works

All command objects support the use of parameters, so you can do the following:

  • Set the arguments of stored procedures.

  • Receive stored procedure return values.

  • Substitute values into SQL queries at runtime.

All parameter objects inherit the MustInherit System.Data.Common.DbParameter class, which implements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required