DekGenius.com
[ Team LiB ] Previous Section Next Section

IDataParameter

System.Data (system.data.dll) interface

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 the version of the value using the SourceVersion property. For example, if the parameter corresponds to a WHERE clause that selects the row that needs to be updated, you use the original value. If the parameter corresponds to the SET clause in an UPDATE statement, use the current value to apply the new information to the data source.

public interface IDataParameter {
// Public Instance Properties
   public DbType DbType{set; get; } 
   public ParameterDirection Direction{set; get; } 
   public bool IsNullable{get; } 
   public string ParameterName{set; get; } 
   public string SourceColumn{set; get; } 
   public DataRowVersion SourceVersion{set; get; } 
   public object Value{set; get; } 
}

Implemented By

IDbDataParameter , System.Data.OleDb.OleDbParameter , System.Data.OracleClient.OracleParameter , System.Data.SqlClient.SqlParameter

Returned By

System.Data.Common.DataAdapter.GetFillParameters( ) , IDataAdapter.GetFillParameters( )

    [ Team LiB ] Previous Section Next Section