Name

IDataParameter

Synopsis

This class represents a parameter for a Command object. Parameters are accessed using the IDbCommand.Parameters collection. Parameters are identified using the ParameterName property. With the SQL Server provider, parameter names are required, and the SQL statement takes the form:

SELECT * FROM Customers WHERE CustomerID = @CustomerID

and the parameter must be named @CustomerID. With the OLE DB provider, however, a question mark placeholder is used instead. Order is important, but the parameter name isn’t. The SQL statement takes the form:

SELECT * FROM Customers WHERE CustomerID = ?

(and the CustomerID value must be first in the parameter collection).

The IDataParameter interface also defines several other important properties. DbType indicates the underlying database data type (although individual ADO.NET providers usually provide an enumeration specific to the data source), and Direction determines whether the parameter is sent to the stored procedure, retrieve from it, or both. You can set the value for the parameter directly using the Value property. You can map it to a column in the DataSet by setting the name of the column in the SourceColumn property. This is primarily useful when you are defining a generic update, insert, or delete command for use with a data adapter. Because this command must work with any modified row, you can’t directly code a parameter value. Instead, the value must be retrieved from the appropriate DataRow. You can also specify ...

Get ADO.NET in a Nutshell 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.