IDbDataAdapter 接口

定义

表示一组与命令有关的属性,用于填充 DataSet 和更新数据源,并由访问关系数据库的 .NET 数据提供程序实现。Represents a set of command-related properties that are used to fill the DataSet and update a data source, and is implemented by .NET data providers that access relational databases.

public interface class IDbDataAdapter : System::Data::IDataAdapter
public interface IDbDataAdapter : System.Data.IDataAdapter
type IDbDataAdapter = interface
    interface IDataAdapter
Public Interface IDbDataAdapter
Implements IDataAdapter
派生
实现

示例

下面的示例使用派生类( SqlCommand 和) SqlDataAdapter SqlConnection 从数据源中选择记录。The following example uses the derived classes, SqlCommand, SqlDataAdapter and SqlConnection, to select records from a data source. DataSet然后返回填充的。The filled DataSet is then returned. 为实现此目的,会将方法传递给已初始化的 DataSet 、连接字符串和作为 TRANSACT-SQL SELECT 语句的查询字符串。To accomplish this, the method is passed an initialized DataSet, a connection string, and a query string that is a Transact-SQL SELECT statement.

private static DataSet SelectRows(DataSet dataset,
    string connectionString,string queryString)
{
    using (SqlConnection connection =
        new SqlConnection(connectionString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(
            queryString, connection);
        adapter.Fill(dataset);
        return dataset;
    }
}

Public Function SelectRows( _
    ByVal dataSet As DataSet, ByVal connectionString As String, _
    ByVal queryString As String) As DataSet

    Using connection As New SqlConnection(connectionString)
        Dim adapter As New SqlDataAdapter()
        adapter.SelectCommand = New SqlCommand( _
            queryString, connection)
        adapter.Fill(dataSet)
        Return dataSet
    End Using
End Function

注解

IDbDataAdapter接口继承自 IDataAdapter 接口,并允许对象创建用于关系数据库的 DataAdapter。The IDbDataAdapter interface inherits from the IDataAdapter interface and allows an object to create a DataAdapter designed for use with a relational database. IDbDataAdapter接口和(可选)实用工具类 DbDataAdapter 允许继承类实现 DataAdapter 类,该类表示数据源与之间的桥梁 DataSetThe IDbDataAdapter interface and, optionally, the utility class, DbDataAdapter, allow an inheriting class to implement a DataAdapter class, which represents the bridge between a data source and a DataSet. 有关 DataAdapter 类的详细信息,请参阅 从 DataAdapter 填充数据集For more information about DataAdapter classes, see Populating a DataSet from a DataAdapter. 有关实现 .NET Framework 数据提供程序的详细信息,请参阅 实现 .NET Framework 数据提供程序For more information about implementing .NET Framework data providers, see Implementing a .NET Framework Data Provider.

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

继承的类 IDbDataAdapter 必须实现继承成员,并且通常定义其他成员来添加特定于提供程序的功能。Classes that inherit IDbDataAdapter must implement the inherited members, and typically define additional members to add provider-specific functionality. 例如, IDbDataAdapter 接口定义 SelectCommand 属性, DbDataAdapter 接口定义 Fill 采用 DataTable 作为参数的方法。For example, the IDbDataAdapter interface defines the SelectCommand property, and the DbDataAdapter interface defines a Fill method that takes a DataTable as a parameter. 反过来, OleDbDataAdapter 该类继承 SelectCommand 属性和 Fill 方法,还定义方法的两个附加重载, Fill 该重载采用 ADO 记录集对象作为参数。In turn, the OleDbDataAdapter class inherits the SelectCommand property and the Fill method, and also defines two additional overloads of the Fill method that take an ADO Recordset object as a parameter.

实施者说明

若要提升 .NET Framework 数据提供程序之间的一致性,请将该继承类命名为 Prv DataAdapter,其中 Prv 是为特定 .NET Framework 数据提供程序命名空间中的所有类指定的统一前缀。To promote consistency among .NET Framework data providers, name the inheriting class in the form Prv DataAdapter where Prv is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. 例如, SqlSqlDataAdapter 命名空间中类的前缀 System.Data.SqlClientFor example, Sql is the prefix of the SqlDataAdapter class in the System.Data.SqlClient namespace.

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

Item 描述Description
PrvDataAdapter ( # A1PrvDataAdapter() 初始化 PrvDataAdapter 类的新实例。Initializes a new instance of the PrvDataAdapter class.
PrvDataAdapter (PrvCommand selectCommand) PrvDataAdapter(PrvCommand selectCommand) 使用指定的 SQL SELECT 语句初始化 PrvDataAdapter 类的新实例。Initializes a new instance of the PrvDataAdapter class with the specified SQL SELECT statement.
PrvDataAdapter (string selectCommandText,string selectConnectionString) PrvDataAdapter(string selectCommandText, string selectConnectionString) 使用 SQL SELECT 语句和连接字符串初始化 PrvDataAdapter 类的新实例。Initializes a new instance of the PrvDataAdapter class with an SQL SELECT statement and a connection string.
PrvDataAdapter (string selectCommandText,PrvConnection selectConnection) PrvDataAdapter(string selectCommandText, PrvConnection selectConnection) 使用 SQL SELECT 语句和 PrvConnection 对象初始化 PrvDataAdapter 类的新实例。Initializes a new instance of the PrvDataAdapter class with an SQL SELECT statement and a PrvConnection object.

属性

DeleteCommand

获取或设置用于从数据集中删除记录的 SQL 语句。Gets or sets an SQL statement for deleting records from the data set.

InsertCommand

获取或设置用于将新记录插入到数据源中的 SQL 语句。Gets or sets an SQL statement used to insert new records into the data source.

MissingMappingAction

指示或指定是否将未映射的源表或列与其源名一起传递以便筛选或引发错误。Indicates or specifies whether unmapped source tables or columns are passed with their source names in order to be filtered or to raise an error.

(继承自 IDataAdapter)
MissingSchemaAction

指示或指定是否将丢失的源表、列及其关系添加到数据集架构中,是否忽略它们或者它们是否会引发错误。Indicates or specifies whether missing source tables, columns, and their relationships are added to the dataset schema, ignored, or cause an error to be raised.

(继承自 IDataAdapter)
SelectCommand

获取或设置用于在数据源中选择记录的 SQL 语句。Gets or sets an SQL statement used to select records in the data source.

TableMappings

指示如何将源表映射到数据集表。Indicates how a source table is mapped to a dataset table.

(继承自 IDataAdapter)
UpdateCommand

获取或设置用于更新数据源中的记录的 SQL 语句。Gets or sets an SQL statement used to update records in the data source.

方法

Fill(DataSet)

添加或更新 DataSet 中的行以匹配使用 DataSet 名称的数据源中的行,并创建一个名为“Table”的 DataTableAdds or updates rows in the DataSet to match those in the data source using the DataSet name, and creates a DataTable named "Table".

(继承自 IDataAdapter)
FillSchema(DataSet, SchemaType)

将名为“Table”的 DataTable 添加到指定的 DataSet,并根据指定的 SchemaType 配置架构以匹配数据源中的架构。Adds a DataTable named "Table" to the specified DataSet and configures the schema to match that in the data source based on the specified SchemaType.

(继承自 IDataAdapter)
GetFillParameters()

获取当执行 SQL SELECT 语句时由用户设置的参数。Gets the parameters set by the user when executing an SQL SELECT statement.

(继承自 IDataAdapter)
Update(DataSet)

从名为“Table”的 DataSet 为指定的 DataTable 中每个已插入、已更新或已删除的行调用相应的 INSERT、UPDATE 或 DELETE 语句。Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataSet from a DataTable named "Table".

(继承自 IDataAdapter)

适用于