다음을 통해 공유


SqlCeDataAdapter 클래스

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

네임스페이스:  System.Data.SqlServerCe
어셈블리:  System.Data.SqlServerCe.dll의 System.Data.SqlServerCe

구문

‘선언
Public NotInheritable Class SqlCeDataAdapter _
    Inherits DbDataAdapter _
    Implements ICloneable
‘사용 방법
Dim instance As SqlCeDataAdapter
public sealed class SqlCeDataAdapter : DbDataAdapter, 
    ICloneable
public ref class SqlCeDataAdapter sealed : public DbDataAdapter, 
    ICloneable
[<SealedAttribute>]
type SqlCeDataAdapter =  
    class
        inherit DbDataAdapter
        interface ICloneable
    end
public final class SqlCeDataAdapter extends DbDataAdapter implements ICloneable

주의

SqlCeDataAdapter는 DataSet과 데이터 원본 사이의 다리 역할을 수행하여 데이터 원본에서 데이터를 검색하거나 데이터 원본에 데이터를 저장하는 데 사용됩니다. SqlCeDataAdapter는 데이터 원본에서 데이터를 DataSet에 로드하는 Fill를 사용하고, DataSet에서 한 변경을 데이터 원본에 다시 보내는 Update를 사용하여 이 연결을 제공합니다.

SqlCeDataAdapter는 DataSet을 채울 때, 반환된 데이터 저장에 필요한 테이블과 열이 없으면 이를 만듭니다. 그러나 MissingSchemaAction 속성이 AddWithKey에 설정되지 않은 경우, 기본 키 정보는 암시적으로 만들어진 스키마에 들어 있지 않습니다. 또한 FillSchema를 사용하여 데이터로 채우기 전에 SqlCeDataAdapter가 기본 키 정보를 포함하는 DataSet의 스키마를 만들도록 할 수 있습니다.

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

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

예제

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

Try
    Dim strDataSource As String
    strDataSource = "" & _
        "Data Source = C:\Program Files\" & _
        "Microsoft SQL Server Compact Edition\v3.5\Samples\" & _
        "Northwind.sdf"
    Dim conn As New SqlCeConnection
    conn.ConnectionString = strDataSource & ";Password='<password>'"

    Dim selectCmd As SqlCeCommand = conn.CreateCommand
    selectCmd.CommandText = "SELECT * FROM Employees"

    Dim adp As New SqlCeDataAdapter(selectCmd)

    Dim ds As New DataSet

    ' Note: Fill will leave the connection in its original state;
    ' In this case, the connection was closed so it will be left closed
    adp.Fill(ds)

    Console.WriteLine(("The SqlCeDataAdapter succesfully filled " & _
                       ds.Tables.Item(0).Rows.Count & " rows in the DataSet!"))
Catch ds As Exception
    Console.WriteLine(ds.Message)
Finally
    Console.WriteLine(vbNewLine & vbNewLine & vbNewLine & _
                      "Press any key to continue...")
    Console.ReadKey()
End Try
try
{
    string strDataSource =
        @"Data Source = C:\Program Files\" +
        @"Microsoft SQL Server Compact Edition\v3.5\Samples\" +
        @"Northwind.sdf";
    SqlCeConnection conn = new SqlCeConnection();
    conn.ConnectionString = strDataSource + ";Password='<password>'";

    SqlCeCommand selectCmd = conn.CreateCommand();
    selectCmd.CommandText = "SELECT * FROM Employees";

    SqlCeDataAdapter adp = new SqlCeDataAdapter(selectCmd);

    DataSet ds = new DataSet();

    // Note: Fill will leave the connection in its original state;
    // In this case, the connection was closed so it will be left closed
    //
    adp.Fill(ds);

    Console.WriteLine("The SqlCeDataAdapter succesfully filled " +
        ds.Tables[0].Rows.Count + " rows in the DataSet!");
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}
finally
{
    Console.WriteLine("\n\n\nPress any key to continue...");
    Console.ReadKey();
}

상속 계층 구조

System. . :: . .Object
  System. . :: . .MarshalByRefObject
    System.ComponentModel. . :: . .Component
      System.Data.Common. . :: . .DataAdapter
        System.Data.Common. . :: . .DbDataAdapter
          System.Data.SqlServerCe..::..SqlCeDataAdapter

스레드로부터의 안전성

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

참고 항목

참조

SqlCeDataAdapter 멤버

System.Data.SqlServerCe 네임스페이스

SqlCeConnection

SqlCeCommand

DataSet

DataTable