IDataParameter IDataParameter IDataParameter IDataParameter Interface

定义

表示 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
派生

示例

下面的示例创建的派生类中,多个实例SqlParameter,直到SqlParameterCollection内的集合, SqlDataAdapterThe 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. 此示例假定DataSet和一个SqlDataAdapter已创建与相应的架构、 命令和连接。This 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接口直接,但创建继承的类的实例IDataParameterAn 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. 例如,Sql的前缀SqlCommand类中System.Data.SqlClient命名空间。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(string name, 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 数据类型,int 大小)PrvParameter(string name, PrvDbType dataType, int size) 初始化使用参数名称、 数据类型和宽度参数类的新实例。Initializes a new instance of the Parameter class with the parameter name, data type, and width.

PrvParameter (字符串名称,PrvDbType 数据类型、 int 大小,字符串 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 (字符串 parameterName、 PrvDbType dbType、 int 大小、 ParameterDirection 方向、 布尔 isNullable、 字节精度、 字节规模、 字符串 srcColumn、 DataRowVersion srcVersion、 对象值)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 DbType DbType DbType

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

Direction Direction Direction Direction

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

IsNullable IsNullable IsNullable IsNullable

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

ParameterName ParameterName ParameterName ParameterName

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

SourceColumn SourceColumn SourceColumn 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 SourceVersion SourceVersion SourceVersion

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

Value Value Value Value

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

适用于