다음을 통해 공유


OleDbDataAdapter 클래스

DataSet을 채우고 데이터 소스를 업데이트하는 데 사용되는 데이터 명령 집합 및 데이터베이스 연결을 나타냅니다.

네임스페이스: System.Data.OleDb
어셈블리: System.Data(system.data.dll)

구문

‘선언
Public NotInheritable Class OleDbDataAdapter
    Inherits DbDataAdapter
    Implements IDbDataAdapter, IDataAdapter, ICloneable
‘사용 방법
Dim instance As OleDbDataAdapter
public sealed class OleDbDataAdapter : DbDataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
public ref class OleDbDataAdapter sealed : public DbDataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
public final class OleDbDataAdapter extends DbDataAdapter implements IDbDataAdapter, IDataAdapter, 
    ICloneable
public final class OleDbDataAdapter extends DbDataAdapter implements IDbDataAdapter, IDataAdapter, 
    ICloneable

설명

OleDbDataAdapter는 데이터를 검색하고 저장하기 위해 DataSet과 데이터 소스 사이를 연결합니다. OleDbDataAdapter는 데이터 소스에서 데이터를 DataSet에 로드하는 Fill를 사용하고, DataSet에서 한 변경을 데이터 소스에 다시 보내는 Update을 사용하여 이 연결을 제공합니다.

OleDbDataAdapterDataSet을 채울 때, 반환된 데이터에 알맞은 테이블과 열이 없으면 이를 만듭니다. 그러나 MissingSchemaAction 속성이 AddWithKey로 설정되지 않은 경우 기본 키 정보는 암시적으로 만들어진 스키마에 포함되지 않습니다. FillSchema를 사용하여 이를 데이터로 채우기 전에 OleDbDataAdapter가 기본 키 정보를 포함하는 DataSet의 스키마를 만들도록 할 수 있습니다. 자세한 내용은 DataSet에 기존 제약 조건 추가을 참조하십시오.

MSDataShape 공급자를 포함하여 일부 OLE DB 공급자는 기본 테이블이나 기본 키 정보를 반환하지 않습니다. 따라서 OleDbDataAdapter는 만들어진 모든 DataTablePrimaryKey 속성을 올바르게 설정할 수 없습니다. 이런 경우 DataSet의 테이블에 대해 기본 키를 명시적으로 지정해야 합니다.

또한 OleDbDataAdapter에는 SelectCommand, InsertCommand, DeleteCommand, UpdateCommandTableMappings 속성이 들어 있어서 데이터를 쉽게 로드하고 업데이트할 수 있습니다.

OleDbDataAdapter의 인스턴스를 만드는 경우 속성이 초기 값으로 설정됩니다. 이러한 값에 대한 목록은 OleDbDataAdapter 생성자를 참조하십시오.

예제

다음 예제에서는 OleDbCommand , OleDbDataAdapterOleDbConnection을 사용하여 Access 데이터 소스에서 레코드를 선택하고 선택한 행으로 DataSet을 채웁니다. 그러면 채워진 DataSet이 반환됩니다. 이를 수행하기 위해 초기화된 DataSet, 연결 문자열 및 SQL SELECT 문인 쿼리 문자열에 메서드가 전달됩니다.

Public Function CreateDataAdapter(ByVal selectCommand As String, _
    ByVal connection As OleDbConnection) As OleDbDataAdapter

    Dim adapter As OleDbDataAdapter = _
        New OleDbDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.InsertCommand = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OleDbCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OleDbCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OleDbType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OleDbType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add( _
        "@CustomerID", OleDbType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add( _
        "@CompanyName", OleDbType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add( _
        "@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function
public static OleDbDataAdapter CreateDataAdapter(string selectCommand,
    OleDbConnection connection)
{
    OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OleDbCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OleDbCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OleDbCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID", 
        OleDbType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName", 
        OleDbType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID", 
        OleDbType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName", 
        OleDbType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID", 
        OleDbType.Char, 5, "CustomerID").SourceVersion = 
        DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID", 
        OleDbType.Char, 5, "CustomerID").SourceVersion = 
        DataRowVersion.Original;

    return adapter;
}
using System;
using System.Data;
using System.Data.OleDb;

class Class1
{
    static void Main()
    {
    }

    public static OleDbDataAdapter CreateDataAdapter(string selectCommand,
        OleDbConnection connection)
    {
        OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, connection);

        adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

        // Create the Insert, Update and Delete commands.
        adapter.InsertCommand = new OleDbCommand(
            "INSERT INTO Customers (CustomerID, CompanyName) " +
            "VALUES (?, ?)");

        adapter.UpdateCommand = new OleDbCommand(
            "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
            "WHERE CustomerID = ?");

        adapter.DeleteCommand = new OleDbCommand(
            "DELETE FROM Customers WHERE CustomerID = ?");

        // Create the parameters.
        adapter.InsertCommand.Parameters.Add("@CustomerID", 
            OleDbType.Char, 5, "CustomerID");
        adapter.InsertCommand.Parameters.Add("@CompanyName", 
            OleDbType.VarChar, 40, "CompanyName");

        adapter.UpdateCommand.Parameters.Add("@CustomerID", 
            OleDbType.Char, 5, "CustomerID");
        adapter.UpdateCommand.Parameters.Add("@CompanyName", 
            OleDbType.VarChar, 40, "CompanyName");
        adapter.UpdateCommand.Parameters.Add("@oldCustomerID", 
            OleDbType.Char, 5, "CustomerID").SourceVersion = 
            DataRowVersion.Original;

        adapter.DeleteCommand.Parameters.Add("@CustomerID", 
            OleDbType.Char, 5, "CustomerID").SourceVersion = 
            DataRowVersion.Original;

        return adapter;
    }

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Data.Common.DataAdapter
         System.Data.Common.DbDataAdapter
          System.Data.OleDb.OleDbDataAdapter

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

OleDbDataAdapter 멤버
System.Data.OleDb 네임스페이스

기타 리소스

DataAdapter 사용