SqlCeDataAdapter クラス
DataSet へのデータの格納およびデータ ソースの更新に使用される、一連のデータ コマンドおよびデータベース接続を表します。
継承階層
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DataAdapter
System.Data.Common.DbDataAdapter
System.Data.SqlServerCe.SqlCeDataAdapter
名前空間: 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 型は、以下のメンバーを公開しています。
コンストラクター
名前 | 説明 | |
---|---|---|
SqlCeDataAdapter() | SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 | |
SqlCeDataAdapter(SqlCeCommand) | SelectCommand プロパティとして SqlCeCommand を指定して、SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 | |
SqlCeDataAdapter(String, SqlCeConnection) | SelectCommand オブジェクトと SqlCeConnection オブジェクトを指定して、SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 | |
SqlCeDataAdapter(String, String) | SelectCommand と接続文字列を指定して、SqlCeDataAdapter クラスの新しいインスタンスを初期化します。 |
Top
プロパティ
名前 | 説明 | |
---|---|---|
AcceptChangesDuringFill | (DataAdapter から継承されます。) | |
AcceptChangesDuringUpdate | (DataAdapter から継承されます。) | |
CanRaiseEvents | (Component から継承されます。) | |
Container | (Component から継承されます。) | |
ContinueUpdateOnError | (DataAdapter から継承されます。) | |
DeleteCommand | データ セットからレコードを削除する SQL ステートメントを取得または設定します。 | |
DesignMode | (Component から継承されます。) | |
Events | (Component から継承されます。) | |
FillCommandBehavior | (DbDataAdapter から継承されます。) | |
FillLoadOption | (DataAdapter から継承されます。) | |
InsertCommand | データ ソースに新しいレコードを挿入する SQL ステートメントを取得または設定します。 | |
MissingMappingAction | (DataAdapter から継承されます。) | |
MissingSchemaAction | (DataAdapter から継承されます。) | |
ReturnProviderSpecificTypes | (DataAdapter から継承されます。) | |
SelectCommand | データ ソース内のレコードを選択する SQL ステートメントを取得または設定します。 | |
Site | (Component から継承されます。) | |
TableMappings | (DataAdapter から継承されます。) | |
UpdateBatchSize | (DbDataAdapter から継承されます。) | |
UpdateCommand | データ ソース内のレコードを更新する SQL ステートメントを取得または設定します。 |
Top
メソッド
Top
イベント
名前 | 説明 | |
---|---|---|
Disposed | (Component から継承されます。) | |
FillError | (DataAdapter から継承されます。) | |
RowUpdated | Update の呼び出し中に、データ ソースに対して更新コマンドが実行された後に発生します。更新が試行されると、このイベントが発生します。 | |
RowUpdating | Update の呼び出し中に、データ ソースに対して更新コマンドが実行される前に発生します。更新が試行されると、このイベントが発生します。 |
Top
明示的なインターフェイスの実装
名前 | 説明 | |
---|---|---|
ICloneable.Clone | このメンバーの説明については、ICloneable.Clone() のトピックを参照してください。 | |
IDbDataAdapter.DeleteCommand | (DbDataAdapter から継承されます。) | |
IDbDataAdapter.InsertCommand | (DbDataAdapter から継承されます。) | |
IDbDataAdapter.SelectCommand | (DbDataAdapter から継承されます。) | |
IDataAdapter.TableMappings | (DataAdapter から継承されます。) | |
IDbDataAdapter.UpdateCommand | (DbDataAdapter から継承されます。) |
Top
説明
SqlCeDataAdapter は DataSet とデータ ソースの間のブリッジとして機能します。データ ソースからのデータ取得や、データ ソースへのデータ保存に使用されます。SqlCeDataAdapter は、このブリッジを提供するために、データ ソース内のデータを DataSet に読み込む Fill、および DataSet での変更をデータ ソースに送り返す Update を使用します。
SqlCeDataAdapter は、DataSet にデータを読み込むときに、返されたデータを格納するテーブルおよび列が存在しない場合は、それらを作成します。ただし、MissingSchemaAction プロパティを AddWithKey に設定しない限り、暗黙的に作成されたスキーマには主キー情報は設定されません。DataSet にデータを格納する前に、FillSchema を使用して、主キー情報を含むスキーマを SqlCeDataAdapter に作成させることもできます。
SqlCeDataAdapter には、データの読み込みと更新を効率的に行うために、SelectCommand、InsertCommand、DeleteCommand、UpdateCommand、TableMappings の各プロパティが用意されています。
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();
}
スレッド セーフ
この型の public static (Microsoft Visual Basic では Shared) のすべてのメンバーは、スレッド セーフです。インスタンス メンバーの場合は、スレッド セーフであるとは限りません。