添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
public ref class OdbcDataAdapter sealed : System::Data::Common::DbDataAdapter
public ref class OdbcDataAdapter sealed : System::Data::Common::DbDataAdapter, ICloneable
public ref class OdbcDataAdapter sealed : System::Data::Common::DbDataAdapter, ICloneable, System::Data::IDbDataAdapter
public sealed class OdbcDataAdapter : System.Data.Common.DbDataAdapter
public sealed class OdbcDataAdapter : System.Data.Common.DbDataAdapter, ICloneable
public sealed class OdbcDataAdapter : System.Data.Common.DbDataAdapter, ICloneable, System.Data.IDbDataAdapter
type OdbcDataAdapter = class
    inherit DbDataAdapter
    interface IDataAdapter
    interface IDbDataAdapter
    interface ICloneable
type OdbcDataAdapter = class
    inherit DbDataAdapter
    interface IDbDataAdapter
    interface IDataAdapter
    interface ICloneable
type OdbcDataAdapter = class
    inherit DbDataAdapter
    interface IDbDataAdapter
    interface ICloneable
    interface IDataAdapter
Public NotInheritable Class OdbcDataAdapter
Inherits DbDataAdapter
Public NotInheritable Class OdbcDataAdapter
Inherits DbDataAdapter
Implements ICloneable
Public NotInheritable Class OdbcDataAdapter
Inherits DbDataAdapter
Implements ICloneable, IDbDataAdapter
OdbcDataAdapter

以下示例使用 OdbcCommand OdbcDataAdapter OdbcConnection 来选择记录,并使用所选行填充 DataSet

public DataSet GetDataSetFromAdapter( DataSet dataSet, string connectionString, string queryString) using (OdbcConnection connection = new OdbcConnection(connectionString)) OdbcDataAdapter adapter = new OdbcDataAdapter(queryString, connection); // Open the connection and fill the DataSet. connection.Open(); adapter.Fill(dataSet); catch (Exception ex) Console.WriteLine(ex.Message); // The connection is automatically closed when the // code exits the using block. return dataSet; Public Function GetDataSetFromAdapter( _ ByVal dataSet As DataSet, ByVal connectionString As String, _ ByVal queryString As String) As DataSet Using connection As New OdbcConnection(connectionString) Dim adapter As New OdbcDataAdapter(queryString, connection) ' Open the connection and fill the DataSet. connection.Open() adapter.Fill(dataSet) Catch ex As Exception Console.WriteLine(ex.Message) End Try ' The connection is automatically closed when the ' code exits the Using block. End Using Return dataSet End Function

OdbcDataAdapter 充当 和数据源之间的桥梁, DataSet 用于检索和保存数据。 OdbcDataAdapter 提供了此桥,方法是使用 Fill 将数据从数据源加载到 中 DataSet ,并使用 Update 将 中 DataSet 所做的更改发送回数据源。

OdbcDataAdapter 当 填充 时 DataSet ,它将为返回的数据创建所需的表和列(如果它们尚不存在)。 但是,除非 将 属性设置为 AddWithKey ,否则 MissingSchemaAction 隐式创建的架构中不包含主键信息。 在使用 填充数据 FillSchema 之前,还可以 OdbcDataAdapter 创建 的 DataSet 架构,包括主键信息。 有关详细信息,请参阅 向数据集添加现有约束

对没有主键列的数据源调用 Fill 方法时, OdbcDataAdapter 会尝试将唯一约束列提升为主键。 在此过程中, OdbcDataAdapter 将唯一约束标记为不可为 null。 除非唯一约束列中存在 null 值,否则此行为有效。 如果存在 null 值,该方法将 Fill 失败,并违反约束。 若要避免这种情况,请不要在唯一约束列中允许 null 值。

由于本机 ODBC 驱动程序的限制,调用 FillSchema 时只返回一个 DataTable 驱动程序。 即使执行需要多个 DataTable 对象的 SQL 批处理语句,也是如此。

OdbcDataAdapter 还包括 、 SelectCommand InsertCommand DeleteCommand UpdateCommand TableMappings 属性,以便于加载和更新数据。