IDataParameter 接口

定义

表示 Command 对象的参数,也可以表示其到 DataSet 列的映射;并由访问数据源的 .NET Framework 数据提供程序实现。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.

public interface class IDataParameter
public interface IDataParameter
type IDataParameter = interface
Public Interface IDataParameter
派生

示例

下面的示例通过 SqlDataAdapter中的 SqlParameterCollection 集合,创建派生类的多个实例,SqlParameterThe following example creates multiple instances of the derived class, SqlParameter, through the SqlParameterCollection collection within the SqlDataAdapter. 这些参数用于从数据源中选择数据,并将数据放入 DataSetThese parameters are used to select data from the data source and place the data in the DataSet. 此示例假设已使用相应的架构、命令和连接创建了 DataSetSqlDataAdapterThis example assumes that a DataSet and a SqlDataAdapter have already been created with the appropriate schema, commands, and connection.

public void AddSqlParameters() 
{
// ...
// create categoriesDataSet and categoriesAdapter
// ...

  categoriesAdapter.SelectCommand.Parameters.Add(
    "@CategoryName", SqlDbType.VarChar, 80).Value = "toasters";
  categoriesAdapter.SelectCommand.Parameters.Add(
    "@SerialNum", SqlDbType.Int).Value = 239;
  categoriesAdapter.Fill(categoriesDataSet);
}
Public Sub AddSqlParameters()
    ' ...
    ' create categoriesDataSet and categoriesAdapter
    ' ...
    categoriesAdapter.SelectCommand.Parameters.Add( _
        "@CategoryName", SqlDbType.VarChar, 80).Value = "toasters"
    categoriesAdapter.SelectCommand.Parameters.Add( _
        "@SerialNum", SqlDbType.Int).Value = 239
    
    categoriesAdapter.Fill(categoriesDataSet)
End Sub  

注解

IDataParameter 接口允许继承类实现一个参数类,该类表示命令对象的参数。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 Configuring Parameters and Parameter Data Types.

应用程序不会直接创建 IDataParameter 接口的实例,而是创建继承 IDataParameter的类的实例。An application does not create an instance of the IDataParameter interface directly, but creates an instance of a class that inherits IDataParameter.

继承 IDataParameter 的类必须实现继承成员,并且通常定义其他成员来添加特定于提供程序的功能。Classes that inherit IDataParameter must implement the inherited members, and typically define additional members to add provider-specific functionality. 例如,IDataParameter 接口定义 DbType 属性。For example, the IDataParameter interface defines the DbType property. 反过来,OleDbParameter 类继承此属性,并且还定义了 OleDbType 属性。In turn, the OleDbParameter class inherits this property, and also defines the OleDbType property.

实施者说明

若要提升 .NET Framework 数据提供程序之间的一致性,请以 Prv 参数的形式命名继承类,其中 Prv 是为特定 .NET Framework 数据提供程序命名空间中的所有类指定的统一前缀。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. 例如,SqlSystem.Data.SqlClient 命名空间中 SqlCommand 类的前缀。For example, Sql is the prefix of the SqlCommand class in the System.Data.SqlClient namespace.

当从 IDataParameter 接口继承时,应实现以下构造函数:When you inherit from the IDataParameter interface, you should implement the following constructors:

Item 说明Description
PrvParameter()PrvParameter() 初始化参数类的新实例。Initializes a new instance of the Parameter class.
PrvParameter (字符串名称,PrvDbType dataType)PrvParameter(string name, PrvDbType dataType) 使用参数名称和数据类型初始化参数类的新实例。Initializes a new instance of the Parameter class with the parameter name and data type.
PrvParameter (字符串名称,对象值)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 (字符串名称,PrvDbType dataType,int size)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)PrvParameter(string name, PrvDbType dataType, int size, string srcColumn) 使用参数名称、数据类型、宽度和源列名称初始化 DbParameter 类的新实例。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 精度,Byte scale,string srcColumn,DataRowVersion srcVersion,object value)PrvParameter(string parameterName, PrvDbType dbType, int size, ParameterDirection direction, Boolean isNullable, Byte precision, Byte scale, string srcColumn, DataRowVersion srcVersion, object value) 使用参数名称、数据类型、宽度、源列名、参数方向、数值精度和其他属性初始化 OleDbParameter 类的新实例。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.

属性

DbType

获取或设置参数的 DbTypeGets or sets the DbType of the parameter.

Direction

获取或设置一个值,该值指示参数是只可输入的参数、只可输出的参数、双向参数还是存储过程返回值参数。Gets or sets a value indicating whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter.

IsNullable

获取一个值,该值指示参数是否接受 null 值。Gets a value indicating whether the parameter accepts null values.

ParameterName

获取或设置 IDataParameter 的名称。Gets or sets the name of the IDataParameter.

SourceColumn

获取或设置映射到 DataSet 并且用于加载或返回 Value 的源列的名称。Gets or sets the name of the source column that is mapped to the DataSet and used for loading or returning the Value.

SourceVersion

获取或设置要在加载 DataRowVersion 时使用的 ValueGets or sets the DataRowVersion to use when loading Value.

Value

获取或设置参数的值。Gets or sets the value of the parameter.

适用于