Export (0) Print
Expand All

IDataParameter Interface

Represents a parameter to a Command object, and optionally, its mapping to DataSet columns; and is implemented by .NET Framework data providers that access data sources.

For a list of all members of this type, see IDataParameter Members.

[Visual Basic]
Public Interface IDataParameter
[C#]
public interface IDataParameter
[C++]
public __gc __interface IDataParameter
[JScript]
public interface IDataParameter

Classes that Implement IDataParameter

Class Description
OdbcParameter Represents a parameter to an OdbcCommand and optionally, its mapping to a DataColumn. This class cannot be inherited.
OleDbParameter Represents a parameter to an OleDbCommand and optionally, its mapping to a DataSet column. This class cannot be inherited.
OracleParameter Represents a parameter to an OracleCommand and optionally, its mapping to a DataColumn. This class cannot be inherited.
SqlCeParameter Represents a parameter to a SqlCeCommand and optionally, its mapping to a DataSet column. This class cannot be inherited.
SqlParameter Represents a parameter to a SqlCommand, and optionally, its mapping to DataSet columns. This class cannot be inherited.

Remarks

The IDataParameter interface allows an inheriting class to implement a Parameter class, which represents a parameter to a Command object. For more information about Parameter classes, see Using Stored Procedures with a Command. For more information about implementing .NET Framework data providers, see Implementing a .NET Framework Data Provider.

An application does not create an instance of the IDataParameter interface directly, but creates an instance of a class that inherits IDataParameter.

Classes that inherit IDataParameter must implement the inherited members, and typically define additional members to add provider-specific functionality. For example, the IDataParameter interface defines the DbType property. In turn, the OleDbParameter class inherits this property, and also defines the OleDbType property.

Notes to Implementers:  To promote consistency among .NET Framework data providers, name the inheriting class in the form Prv Parameter where Prv is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. For example, Sql is the prefix of the SqlCommand class in the System.Data.SqlClient namespace.

When you inherit from the IDataParameter interface, you should implement the following constructors:

Item Description
PrvParameter() Initializes a new instance of the Parameter class.
PrvParameter(string name, PrvDbType dataType) Initializes a new instance of the Parameter class with the parameter name and data type.
PrvParameter(string name, object value) Initializes a new instance of the Parameter class with the parameter name and an object that is the value of the Parameter.
PrvParameter(string name, PrvDbType dataType, int size) Initializes a new instance of the Parameter class with the parameter name, data type, and width.
PrvParameter(string name, PrvDbType dataType, int size, string srcColumn) Initializes a new instance of the DbParameter class with the parameter name, data type, width, and source column name.
PrvParameter(string parameterName, PrvDbType dbType, int size, ParameterDirection direction, Boolean isNullable, Byte precision, Byte scale, string srcColumn, DataRowVersion srcVersion, object value) Initializes a new instance of the OleDbParameter class with the parameter name, data type, width, source column name, parameter direction, numeric precision, and other properties.

Example

[Visual Basic, C#, C++] The following example creates multiple instances of the derived class, SqlParameter, through the SqlParameterCollection collection within the SqlDataAdapter. These parameters are used to select data from the data source and place the data in the DataSet. This example assumes that a DataSet and a SqlDataAdapter have already been created with the appropriate schema, commands, and connection.

[Visual Basic] 
Public Sub AddSqlParameters()
    ' ...
    ' create myDataSet and myDataAdapter
    ' ...
    myDataAdapter.SelectCommand.Parameters.Add("@CategoryName", SqlDbType.VarChar, 80).Value = "toasters"
    myDataAdapter.SelectCommand.Parameters.Add("@SerialNum", SqlDbType.Int).Value = 239
    
    myDataAdapter.Fill(myDataSet)
End Sub 'AddSqlParameters 

[C#] 
public void AddSqlParameters() 
{
// ...
// create myDataSet and myDataAdapter
// ...

  myDataAdapter.SelectCommand.Parameters.Add("@CategoryName", SqlDbType.VarChar, 80).Value = "toasters";
  myDataAdapter.SelectCommand.Parameters.Add("@SerialNum", SqlDbType.Int).Value = 239;
  myDataAdapter.Fill(myDataSet);

}

[C++] 
public:
void AddSqlParameters() 
{
// ...
// create myDataSet and myDataAdapter
// ...

  myDataAdapter->SelectCommand->Parameters->Add(S"@CategoryName", SqlDbType::VarChar, 80)->Value = S"toasters";
  myDataAdapter->SelectCommand->Parameters->Add(S"@SerialNum", SqlDbType::Int)->Value = __box(239);
  myDataAdapter->Fill(myDataSet);

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Data

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Data (in System.Data.dll)

See Also

IDataParameter Members | System.Data Namespace

Show:
© 2014 Microsoft