SqlDataAdapterとは? わかりやすく解説

SqlDataAdapter イベント


SqlDataAdapter クラス

DataSet へのデータの格納および SQL Server データベースの更新に使用される、一連のデータ コマンドおよびデータベース接続を表します。このクラスは継承できません。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public NotInheritable Class
 SqlDataAdapter
    Inherits DbDataAdapter
    Implements IDbDataAdapter, IDataAdapter, ICloneable
Dim instance As SqlDataAdapter
public sealed class SqlDataAdapter : DbDataAdapter,
 IDbDataAdapter, IDataAdapter, ICloneable
public ref class SqlDataAdapter sealed : public
 DbDataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
public final class SqlDataAdapter extends DbDataAdapter
 implements IDbDataAdapter, IDataAdapter, 
    ICloneable
public final class SqlDataAdapter extends
 DbDataAdapter implements IDbDataAdapter, IDataAdapter, 
    ICloneable
解説解説

SqlDataAdapter は、DataSet と SQL Server の間でデータを取得および保存するための、ブリッジの役割を果たします。SqlDataAdapter は、このブリッジを提供するために、データ ソースに対して適切な Transact-SQL ステートメントを使用して、DataSet 内のデータをデータ ソース内のデータと一致するように変更する Fill と、データ ソース内のデータを DataSet 内のデータと一致するように変更する Update で、割り当てを行います。

SqlDataAdapter は、DataSet にデータを読み込むときに、返されたデータを格納するテーブルおよび列が存在しない場合は、それらを作成します。ただし、MissingSchemaAction プロパティを AddWithKey に設定しない限り、暗黙的に作成されたスキーマには主キー情報は設定されません。DataSet にデータを格納する前に、FillSchema を使用して、主キー情報を含むスキーマを SqlDataAdapter に作成させることもできます。詳細については、「DataSet への既存の制約の追加」を参照してください。

SqlDataAdapter は、SQL Server データベースへの接続のパフォーマンスを向上させるために、SqlConnection および SqlCommand と組み合わせて使用します。

SqlDataAdapter には、データの読み込みと更新を効率的に行うために、SelectCommand、InsertCommand、DeleteCommand、UpdateCommand、TableMappings の各プロパティも用意されています。

SqlDataAdapter のインスタンスを作成すると、読み書き可能プロパティが初期値に設定されます。これらの初期値の一覧については、SqlDataAdapter コンストラクタのトピックを参照してください。

使用例使用例

SqlCommand、SqlDataAdapter、および SqlConnection を使用して、データベースからレコードを選択し、選択した行を DataSet に格納する例を次に示します。次に、格納された DataSet が返されます。そのために、初期化された DataSet、接続文字列、および Transact-SQL SELECT ステートメントのクエリ文字列がメソッドに渡されます。

Public Function SelectRows( _
    ByVal dataSet As DataSet, ByVal
 connectionString As String, _
    ByVal queryString As String)
 As DataSet

    Using connection As New SqlConnection(connectionString)
        Dim adapter As New
 SqlDataAdapter()
        adapter.SelectCommand = New SqlCommand( _
            queryString, connection)
        adapter.Fill(dataSet)
        Return dataSet
    End Using
End Function
private static DataSet SelectRows(DataSet dataset
,
    string connectionString,string queryString)
 
{
    using (SqlConnection connection = 
        new SqlConnection(connectionString))
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(
            queryString, connection);
        adapter.Fill(dataset);
        return dataset;
    }
}

継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Data.Common.DataAdapter
         System.Data.Common.DbDataAdapter
          System.Data.SqlClient.SqlDataAdapter
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter コンストラクタ ()

SqlDataAdapter クラスの新しいインスタンスを初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Dim instance As New SqlDataAdapter
public SqlDataAdapter ()
public:
SqlDataAdapter ()
public SqlDataAdapter ()
public function SqlDataAdapter ()
解説解説

SqlDataAdapter のインスタンスを作成すると、次のように各読み書き可能プロパティが初期値に設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティを個別に呼び出して変更できます。

使用例使用例

SqlDataAdapter を作成し、そのプロパティの一部を設定する例を次に示します。

Public Function CreateSqlDataAdapter(ByVal
 connection As SqlConnection) As SqlDataAdapter
    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the commands.
    adapter.SelectCommand = New SqlCommand( _
        "SELECT CustomerID, CompanyName FROM CUSTOMERS",
 connection)
    adapter.InsertCommand = New SqlCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) "
 & _
         "VALUES (@CustomerID, @CompanyName)", connection)
    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID", connection)
    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID",
 connection)

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

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

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

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(SqlConnection
 connection)
{
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the commands.
    adapter.SelectCommand = new SqlCommand(
        "SELECT CustomerID, CompanyName FROM CUSTOMERS", connection);
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)", connection);
    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID", connection);
    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);

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

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

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

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter コンストラクタ (SqlCommand)

SelectCommand プロパティとして SqlCommand を指定して、SqlDataAdapter クラスの新しいインスタンスを初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub New ( _
    selectCommand As SqlCommand _
)
Dim selectCommand As SqlCommand

Dim instance As New SqlDataAdapter(selectCommand)
public SqlDataAdapter (
    SqlCommand selectCommand
)
public:
SqlDataAdapter (
    SqlCommand^ selectCommand
)
public SqlDataAdapter (
    SqlCommand selectCommand
)
public function SqlDataAdapter (
    selectCommand : SqlCommand
)

パラメータ

selectCommand

Transact-SQL SELECT ステートメントまたはストアド プロシージャである SqlCommand。SqlDataAdapter の SelectCommand プロパティとして設定されます。

解説解説

SqlDataAdapter コンストラクタの実装により、SelectCommand プロパティを selectCommand パラメータで指定した値に設定します。

SqlDataAdapter のインスタンスを作成すると、次のように各読み書き可能プロパティが初期値に設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティを個別に呼び出して変更できます。

作成済みの SqlCommand に SelectCommand またはその他のいずれかのコマンド プロパティが割り当てられた場合、SqlCommand のクローンは作成されません。SelectCommand によって、作成済みの SqlCommand オブジェクトへの参照が維持されます。

使用例使用例

SqlDataAdapter を作成し、そのプロパティの一部を設定する例を次に示します。

Public Function CreateSqlDataAdapter(ByVal
 selectCommand As SqlCommand, _
    ByVal connection As SqlConnection) As
 SqlDataAdapter

    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter(selectCommand)
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

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

    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID", connection)

    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID",
 connection)

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

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

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

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(SqlCommand
 selectCommand,
    SqlConnection connection)
{
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the other commands.
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)", connection);

    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID", connection);

    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);

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

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

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

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter コンストラクタ (String, SqlConnection)

SelectCommand オブジェクトと SqlConnection オブジェクトを指定して、SqlDataAdapter クラスの新しいインスタンスを初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub New ( _
    selectCommandText As String, _
    selectConnection As SqlConnection _
)
Dim selectCommandText As String
Dim selectConnection As SqlConnection

Dim instance As New SqlDataAdapter(selectCommandText,
 selectConnection)
public SqlDataAdapter (
    string selectCommandText,
    SqlConnection selectConnection
)
public:
SqlDataAdapter (
    String^ selectCommandText, 
    SqlConnection^ selectConnection
)
public SqlDataAdapter (
    String selectCommandText, 
    SqlConnection selectConnection
)
public function SqlDataAdapter (
    selectCommandText : String, 
    selectConnection : SqlConnection
)

パラメータ

selectCommandText

Transact-SQL SELECT ステートメントまたはストアド プロシージャである String。SqlDataAdapter の SelectCommand プロパティによって使用されます。

selectConnection

接続を表す SqlConnection。

解説解説

SqlDataAdapter の実装では、SqlConnection が開いていない場合は、接続が開かれ、再び閉じられます。これは、アプリケーションで複数の SqlDataAdapter オブジェクトの Fill メソッドを呼び出す必要がある場合に効果的です。SqlConnection が既に開いている場合、その接続を閉じるには、明示的に Close または Dispose を呼び出す必要があります。

SqlDataAdapter のインスタンスを作成すると、次のように各読み書き可能プロパティが初期値に設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティを個別に呼び出して変更できます。

使用例使用例

SqlDataAdapter を作成し、そのプロパティの一部を設定する例を次に示します。

Public Function CreateSqlDataAdapter(ByVal
 commandText As String, _
    ByVal connection As SqlConnection) As
 SqlDataAdapter

    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter(commandText, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

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

    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID")

    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID")

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

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

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

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(string
 commandText,
    SqlConnection connection)
{
    SqlDataAdapter adapter = new SqlDataAdapter(commandText, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the other commands.
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)");

    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID");

    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID");

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

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

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

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter コンストラクタ

SqlDataAdapter クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
SqlDataAdapter () SqlDataAdapter クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

SqlDataAdapter (SqlCommand) SelectCommand プロパティとして SqlCommand を指定して、SqlDataAdapter クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

SqlDataAdapter (String, SqlConnection) SelectCommand オブジェクトと SqlConnection オブジェクトを指定して、SqlDataAdapter クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

SqlDataAdapter (String, String) SelectCommand と接続文字列を指定して、SqlDataAdapter クラスの新しいインスタンスを初期化します。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

SqlDataAdapter クラス
SqlDataAdapter メンバ
System.Data.SqlClient 名前空間

その他の技術情報

ADO.NET でのデータの変更
.NET Framework Data Provider for SQL Server の使用

SqlDataAdapter コンストラクタ (String, String)

SelectCommand と接続文字列を指定して、SqlDataAdapter クラスの新しいインスタンスを初期化します。

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub New ( _
    selectCommandText As String, _
    selectConnectionString As String _
)
Dim selectCommandText As String
Dim selectConnectionString As String

Dim instance As New SqlDataAdapter(selectCommandText,
 selectConnectionString)
public SqlDataAdapter (
    string selectCommandText,
    string selectConnectionString
)
public:
SqlDataAdapter (
    String^ selectCommandText, 
    String^ selectConnectionString
)
public SqlDataAdapter (
    String selectCommandText, 
    String selectConnectionString
)
public function SqlDataAdapter (
    selectCommandText : String, 
    selectConnectionString : String
)

パラメータ

selectCommandText

Transact-SQL SELECT ステートメントまたはストアド プロシージャである String。SqlDataAdapter の SelectCommand プロパティによって使用されます。

selectConnectionString

接続文字列。

解説解説

SqlDataAdapter コンストラクタのこのオーバーロードでは、selectCommandText パラメータを使用して SelectCommand プロパティを設定します。SqlDataAdapter は、selectConnectionString パラメータを使用して接続を作成および維持します。

SqlDataAdapter のインスタンスを作成すると、次のように各読み書き可能プロパティが初期値に設定されます。

プロパティ

初期値

MissingMappingAction

MissingMappingAction.Passthrough

MissingSchemaAction

MissingSchemaAction.Add

これらのプロパティの値は、各プロパティを個別に呼び出して変更できます。

使用例使用例

SqlDataAdapter を作成し、そのプロパティの一部を設定する例を次に示します。

Public Function CreateSqlDataAdapter(ByVal
 commandText As String, _
    ByVal connectionString As String)
 As SqlDataAdapter

    Dim adapter As SqlDataAdapter = New
 SqlDataAdapter(commandText, connectionString)
    Dim connection As SqlConnection = adapter.SelectCommand.Connection

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

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

    adapter.UpdateCommand = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName
 = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID", connection)

    adapter.DeleteCommand = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID",
 connection)

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

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

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

    Return adapter
End Function
public static SqlDataAdapter CreateSqlDataAdapter(string
 commandText,
    string connectionString)
{
    SqlDataAdapter adapter = new SqlDataAdapter(commandText, connectionString);
    SqlConnection connection = adapter.SelectCommand.Connection;

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the commands.
    adapter.InsertCommand = new SqlCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (@CustomerID, @CompanyName)", connection);

    adapter.UpdateCommand = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName
 " +
        "WHERE CustomerID = @oldCustomerID", connection);

    adapter.DeleteCommand = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);

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

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

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

    return adapter;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

SqlDataAdapter プロパティ


パブリック プロパティパブリック プロパティ

( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ AcceptChangesDuringFill  Fill 操作中に DataTable に DataRow が追加された後で、その行に対して AcceptChanges を呼び出すかどうかを示す値を取得または設定します。 ( DataAdapter から継承されます。)
パブリック プロパティ AcceptChangesDuringUpdate  Update で AcceptChanges が呼び出されるかどうかを取得または設定します。 ( DataAdapter から継承されます。)
パブリック プロパティ Container  Component を格納している IContainer を取得します。 ( Component から継承されます。)
パブリック プロパティ ContinueUpdateOnError  行の更新中にエラーが発生したときに、例外を生成するかどうかを指定する値を取得または設定します。 ( DataAdapter から継承されます。)
パブリック プロパティ FillLoadOption  アダプタが DbDataReader から DataTable にデータを読み込む方法を決定する LoadOption を取得または設定します。 ( DataAdapter から継承されます。)
パブリック プロパティ MissingMappingAction  一致するテーブルまたは列が受信データに含まれていない場合に実行するアクションを決定します。 ( DataAdapter から継承されます。)
パブリック プロパティ MissingSchemaAction  既存の DataSet スキーマが受信データと一致しないときに実行するアクションを決定します。 ( DataAdapter から継承されます。)
パブリック プロパティ ReturnProviderSpecificTypes  Fill メソッドがプロバイダ固有の値、または共通の CLS 準拠の値のどちらを返すかを取得または設定します。 ( DataAdapter から継承されます。)
パブリック プロパティ Site  Component の ISite を取得または設定します。 ( Component から継承されます。)
パブリック プロパティ TableMappings  ソース テーブルと DataTable との間のマスター マップを提供するコレクションを取得します。 ( DataAdapter から継承されます。)
パブリック プロパティ UpdateCommand データ ソース内のレコードを更新するための Transact-SQL ステートメントまたはストアド プロシージャを取得または設定します。
プロテクト プロパティプロテクト プロパティ
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.Data.IDbDataAdapter.UpdateCommand このメンバの説明については、UpdateCommand のトピックを参照してください。
参照参照

関連項目

SqlDataAdapter クラス
System.Data.SqlClient 名前空間

その他の技術情報

ADO.NET でのデータの変更
ADO.NET でのデータへの接続およびデータの取得
.NET Framework Data Provider for SQL Server の使用

SqlDataAdapter メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド CreateObjRef  リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド Dispose  オーバーロードされます。 Component によって使用されているリソースを解放します。 ( Component から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。)
パブリック メソッド Fill  オーバーロードされます。 DataSet または DataTable にデータを読み込みます。 ( DbDataAdapter から継承されます。)
パブリック メソッド FillSchema  オーバーロードされます。 DataTable を DataSet に追加し、データ ソース内のスキーマと一致するようにスキーマを設定します。 ( DbDataAdapter から継承されます。)
パブリック メソッド GetFillParameters  SQL SELECT ステートメントの実行時にユーザーが設定したパラメータを取得します。 ( DbDataAdapter から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。)
パブリック メソッド GetLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド InitializeLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ResetFillLoadOption  FillLoadOption を既定の状態にリセットし、Fill で AcceptChangesDuringFill を受け入れるようにします。 ( DataAdapter から継承されます。)
パブリック メソッド ShouldSerializeAcceptChangesDuringFill  AcceptChangesDuringFill プロパティを永続化する必要があるかどうかを決定します。 ( DataAdapter から継承されます。)
パブリック メソッド ShouldSerializeFillLoadOption  FillLoadOption プロパティを永続化する必要があるかどうかを決定します。 ( DataAdapter から継承されます。)
パブリック メソッド ToString  Component の名前を格納している String を返します (存在する場合)。このメソッドはオーバーライドできません。 ( Component から継承されます。)
パブリック メソッド Update  オーバーロードされます。 DataSet 内の挿入行、更新行、または削除行に対して、INSERT、UPDATE、または DELETE ステートメントを個別に呼び出します。 ( DbDataAdapter から継承されます。)
プロテクト メソッドプロテクト メソッド
  名前 説明
プロテクト メソッド AddToBatch  IDbCommand を現在のバッチに追加します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド ClearBatch  バッチからすべての IDbCommand オブジェクトを削除します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド CloneInternals  この DataAdapter のインスタンスのコピーを作成します。 ( DataAdapter から継承されます。)
プロテクト メソッド CreateRowUpdatedEvent  RowUpdatedEventArgs クラスの新しいインスタンスを初期化します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド CreateRowUpdatingEvent  RowUpdatingEventArgs クラスの新しいインスタンスを初期化します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド CreateTableMappings  新しい DataTableMappingCollection を作成します。 ( DataAdapter から継承されます。)
プロテクト メソッド Dispose  オーバーロードされます。 Component によって使用されているリソースを解放します。 ( Component から継承されます。)
プロテクト メソッド ExecuteBatch  現在のバッチを実行します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド Fill  オーバーロードされます。 DataSet または DataTable にデータを読み込みます。 ( DbDataAdapter から継承されます。)
プロテクト メソッド FillSchema  オーバーロードされます。 DataTable を DataSet に追加し、データ ソース内のスキーマと一致するようにスキーマを設定します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド Finalize  Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 ( Component から継承されます。)
プロテクト メソッド GetBatchedParameter  現在のバッチのコマンドの 1 つから IDataParameter を返します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド GetService  Component またはその Container で提供されるサービスを表すオブジェクトを返します。 ( Component から継承されます。)
プロテクト メソッド HasTableMappings  DataTableMappingCollection が作成されているかどうかを示します。 ( DataAdapter から継承されます。)
プロテクト メソッド InitializeBatching  DbDataAdapter のバッチ処理を初期化します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド MemberwiseClone  オーバーロードされます。 ( MarshalByRefObject から継承されます。)
プロテクト メソッド OnFillError  Fill 中にエラーが発生したときに呼び出されます。 ( DataAdapter から継承されます。)
プロテクト メソッド OnRowUpdated  .NET Framework データ プロバイダの RowUpdated イベントを発生させます。 ( DbDataAdapter から継承されます。)
プロテクト メソッド OnRowUpdating  .NET Framework データ プロバイダの RowUpdating イベントを発生させます。 ( DbDataAdapter から継承されます。)
プロテクト メソッド ShouldSerializeTableMappings  1 つ以上の DataTableMapping オブジェクトが存在し、それらを永続化する必要があるかどうかを確認します。 ( DataAdapter から継承されます。)
プロテクト メソッド TerminateBatching  DbDataAdapter のバッチ処理を終了します。 ( DbDataAdapter から継承されます。)
プロテクト メソッド Update  オーバーロードされます。 DataSet 内の挿入行、更新行、または削除行に対して、INSERT、UPDATE、または DELETE ステートメントを個別に呼び出します。 ( DbDataAdapter から継承されます。)
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.ICloneable.Clone このメンバの説明については、Clone のトピックを参照してください。
参照参照

関連項目

SqlDataAdapter クラス
System.Data.SqlClient 名前空間

その他の技術情報

ADO.NET でのデータの変更
ADO.NET でのデータへの接続およびデータの取得
.NET Framework Data Provider for SQL Server の使用

SqlDataAdapter メンバ

DataSet へのデータの格納および SQL Server データベースの更新に使用される、一連のデータ コマンドおよびデータベース接続を表します。このクラスは継承できません。

SqlDataAdapter データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ AcceptChangesDuringFill  Fill 操作中に DataTable に DataRow が追加された後で、その行に対して AcceptChanges を呼び出すかどうかを示す値を取得または設定します。(DataAdapter から継承されます。)
パブリック プロパティ AcceptChangesDuringUpdate  Update で AcceptChanges が呼び出されるかどうかを取得または設定します。(DataAdapter から継承されます。)
パブリック プロパティ Container  Component を格納している IContainer を取得します。(Component から継承されます。)
パブリック プロパティ ContinueUpdateOnError  行の更新中にエラーが発生したときに、例外を生成するかどうかを指定する値を取得または設定します。(DataAdapter から継承されます。)
パブリック プロパティ FillLoadOption  アダプタが DbDataReader から DataTable にデータを読み込む方法を決定する LoadOption を取得または設定します。(DataAdapter から継承されます。)
パブリック プロパティ MissingMappingAction  一致するテーブルまたは列が受信データに含まれていない場合に実行するアクションを決定します。(DataAdapter から継承されます。)
パブリック プロパティ MissingSchemaAction  既存の DataSet スキーマが受信データと一致しないときに実行するアクションを決定します。(DataAdapter から継承されます。)
パブリック プロパティ ReturnProviderSpecificTypes  Fill メソッドがプロバイダ固有の値、または共通の CLS 準拠の値のどちらを返すかを取得または設定します。(DataAdapter から継承されます。)
パブリック プロパティ Site  Component の ISite を取得または設定します。(Component から継承されます。)
パブリック プロパティ TableMappings  ソース テーブルと DataTable との間のマスター マップを提供するコレクションを取得します。(DataAdapter から継承されます。)
パブリック プロパティ UpdateCommand データ ソース内のレコードを更新するための Transact-SQL ステートメントまたはストアド プロシージャを取得または設定します。
プロテクト プロパティプロテクト プロパティ
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド CreateObjRef  リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 (MarshalByRefObject から継承されます。)
パブリック メソッド Dispose  オーバーロードされます。 Component によって使用されているリソースを解放します。 (Component から継承されます。)
パブリック メソッド Equals  オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。)
パブリック メソッド Fill  オーバーロードされます。 DataSet または DataTable にデータを読み込みます。 (DbDataAdapter から継承されます。)
パブリック メソッド FillSchema  オーバーロードされます。 DataTable を DataSet に追加し、データ ソース内のスキーマと一致するようにスキーマを設定します。 (DbDataAdapter から継承されます。)
パブリック メソッド GetFillParameters  SQL SELECT ステートメントの実行時にユーザーが設定したパラメータを取得します。 (DbDataAdapter から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。)
パブリック メソッド GetLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド InitializeLifetimeService  対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ResetFillLoadOption  FillLoadOption を既定の状態にリセットし、Fill で AcceptChangesDuringFill を受け入れるようにします。 (DataAdapter から継承されます。)
パブリック メソッド ShouldSerializeAcceptChangesDuringFill  AcceptChangesDuringFill プロパティを永続化する必要があるかどうかを決定します。 (DataAdapter から継承されます。)
パブリック メソッド ShouldSerializeFillLoadOption  FillLoadOption プロパティを永続化する必要があるかどうかを決定します。 (DataAdapter から継承されます。)
パブリック メソッド ToString  Component の名前を格納している String を返します (存在する場合)。このメソッドはオーバーライドできません。 (Component から継承されます。)
パブリック メソッド Update  オーバーロードされます。 DataSet 内の挿入行、更新行、または削除行に対して、INSERT、UPDATE、または DELETE ステートメントを個別に呼び出します。 (DbDataAdapter から継承されます。)
プロテクト メソッドプロテクト メソッド
  名前 説明
プロテクト メソッド AddToBatch  IDbCommand を現在のバッチに追加します。 (DbDataAdapter から継承されます。)
プロテクト メソッド ClearBatch  バッチからすべての IDbCommand オブジェクトを削除します。 (DbDataAdapter から継承されます。)
プロテクト メソッド CloneInternals  この DataAdapter のインスタンスのコピーを作成します。 (DataAdapter から継承されます。)
プロテクト メソッド CreateRowUpdatedEvent  RowUpdatedEventArgs クラスの新しいインスタンスを初期化します。 (DbDataAdapter から継承されます。)
プロテクト メソッド CreateRowUpdatingEvent  RowUpdatingEventArgs クラスの新しいインスタンスを初期化します。 (DbDataAdapter から継承されます。)
プロテクト メソッド CreateTableMappings  新しい DataTableMappingCollection を作成します。 (DataAdapter から継承されます。)
プロテクト メソッド Dispose  オーバーロードされます。 Component によって使用されているリソースを解放します。 (Component から継承されます。)
プロテクト メソッド ExecuteBatch  現在のバッチを実行します。 (DbDataAdapter から継承されます。)
プロテクト メソッド Fill  オーバーロードされます。 DataSet または DataTable にデータを読み込みます。 (DbDataAdapter から継承されます。)
プロテクト メソッド FillSchema  オーバーロードされます。 DataTable を DataSet に追加し、データ ソース内のスキーマと一致するようにスキーマを設定します。 (DbDataAdapter から継承されます。)
プロテクト メソッド Finalize  Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 (Component から継承されます。)
プロテクト メソッド GetBatchedParameter  現在のバッチのコマンドの 1 つから IDataParameter を返します。 (DbDataAdapter から継承されます。)
プロテクト メソッド GetService  Component またはその Container で提供されるサービスを表すオブジェクトを返します。 (Component から継承されます。)
プロテクト メソッド HasTableMappings  DataTableMappingCollection が作成されているかどうかを示します。 (DataAdapter から継承されます。)
プロテクト メソッド InitializeBatching  DbDataAdapter のバッチ処理を初期化します。 (DbDataAdapter から継承されます。)
プロテクト メソッド MemberwiseClone  オーバーロードされます。 ( MarshalByRefObject から継承されます。)
プロテクト メソッド OnFillError  Fill 中にエラーが発生したときに呼び出されます。 (DataAdapter から継承されます。)
プロテクト メソッド OnRowUpdated  .NET Framework データ プロバイダの RowUpdated イベントを発生させます。 (DbDataAdapter から継承されます。)
プロテクト メソッド OnRowUpdating  .NET Framework データ プロバイダの RowUpdating イベントを発生させます。 (DbDataAdapter から継承されます。)
プロテクト メソッド ShouldSerializeTableMappings  1 つ以上の DataTableMapping オブジェクトが存在し、それらを永続化する必要があるかどうかを確認します。 (DataAdapter から継承されます。)
プロテクト メソッド TerminateBatching  DbDataAdapter のバッチ処理を終了します。 (DbDataAdapter から継承されます。)
プロテクト メソッド Update  オーバーロードされます。 DataSet 内の挿入行、更新行、または削除行に対して、INSERT、UPDATE、または DELETE ステートメントを個別に呼び出します。 (DbDataAdapter から継承されます。)
パブリック イベントパブリック イベント
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.ICloneable.Clone このメンバの説明については、Clone のトピックを参照してください。
インターフェイスの明示的な実装 System.Data.IDbDataAdapter.UpdateCommand このメンバの説明については、UpdateCommand のトピックを参照してください。
参照参照

関連項目

SqlDataAdapter クラス
System.Data.SqlClient 名前空間

その他の技術情報

ADO.NET でのデータの変更
ADO.NET でのデータへの接続およびデータの取得
.NET Framework Data Provider for SQL Server の使用



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「SqlDataAdapter」の関連用語

SqlDataAdapterのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlDataAdapterのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS