Share via


SqlCeDataAdapter クラス

DataSet へのデータの格納およびデータ ソースの更新に使用される、一連のデータ コマンドおよびデータベース接続を表します。

名前空間:  System.Data.SqlServerCe
アセンブリ:  System.Data.SqlServerCe (System.Data.SqlServerCe.dll)

構文

'宣言
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 に設定しない限り、暗黙的に作成されたスキーマには主キー情報は設定されません。DataSet にデータを格納する前に、FillSchema を使用して、主キー情報を含むスキーマを SqlCeDataAdapter に作成させることもできます。

SqlCeDataAdapter には、データの読み込みと更新を効率的に行うために、SelectCommandInsertCommandDeleteCommandUpdateCommandTableMappings の各プロパティが用意されています。

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