Using Parameters

The Command object contains a collection of stored procedure parameters named, aptly enough, Parameters. If your stored procedure requires input parameters or returns values using one or more output parameters, you will need to add each parameter to the Parameters collection.

For example, consider the Customer_GetByID stored procedure you created at the beginning of this hour. To set up the parameter object, the first step is to declare the parameter, as follows:

Dim parameterCustomerID As SqlParameter = New SqlParameter("@CustomerID", _
                                                   SqlDbType.NChar, 4)

Note that the name of the parameter must match the name of the parameter declared inside the stored procedure. Additionally, the type must match, as well. After the parameter ...

Get Sams Teach Yourself ADO.NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.