SqlDataAdapter.UpdateCommand プロパティ
アセンブリ: System.Data (system.data.dll 内)

Dim instance As SqlDataAdapter Dim value As SqlCommand value = instance.UpdateCommand instance.UpdateCommand = value
/** @property */ public SqlCommand get_UpdateCommand () /** @property */ public void set_UpdateCommand (SqlCommand value)
public function get UpdateCommand () : SqlCommand public function set UpdateCommand (value : SqlCommand)
Update 処理中に、DataSet 内の変更行に対応するデータベース内のレコードを更新するための SqlCommand。

Update 処理中に、このプロパティが設定されておらず、DataSet に主キー情報が存在する場合、SelectCommand プロパティを設定し、SqlCommandBuilder を使用しているときは、UpdateCommand が自動的に生成されます。続いて、設定していない追加のコマンドが、SqlCommandBuilder によって生成されます。この生成ロジックでは、DataSet 内にキー列情報が存在している必要があります。詳細については、「コマンドの自動生成」を参照してください。
作成済みの SqlCommand に UpdateCommand が割り当てられた場合、SqlCommand のクローンは作成されません。UpdateCommand によって、作成済みの SqlCommand オブジェクトへの参照が維持されます。
![]() |
---|
このコマンドの実行によって行が返される場合、SqlCommand オブジェクトの UpdatedRowSource プロパティの設定によっては、更新された行が DataSet にマージされることがあります。 |

SqlDataAdapter を作成し、SelectCommand、InsertCommand、UpdateCommand、および DeleteCommand の各プロパティを設定する例を次に示します。ここでは、SqlConnection オブジェクトが既に作成されていることを前提にしています。
Public Function CreateCustomerAdapter( _ ByVal connection As SqlConnection) As SqlDataAdapter Dim adapter As SqlDataAdapter = New SqlDataAdapter() ' Create the SelectCommand. Dim command As SqlCommand = New SqlCommand( _ "SELECT * FROM Customers " & _ "WHERE Country = @Country AND City = @City", connection) ' Add the parameters for the SelectCommand. command.Parameters.Add("@Country", SqlDbType.NVarChar, 15) command.Parameters.Add("@City", SqlDbType.NVarChar, 15) adapter.SelectCommand = command ' Create the InsertCommand. command = New SqlCommand( _ "INSERT INTO Customers (CustomerID, CompanyName) " & _ "VALUES (@CustomerID, @CompanyName)", connection) ' Add the parameters for the InsertCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID") command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName") adapter.InsertCommand = command ' Create the UpdateCommand. command = New SqlCommand( _ "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " & _ "WHERE CustomerID = @oldCustomerID", connection) ' Add the parameters for the UpdateCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID") command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName") Dim parameter As SqlParameter = command.Parameters.Add( _ "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID") parameter.SourceVersion = DataRowVersion.Original adapter.UpdateCommand = command ' Create the DeleteCommand. command = New SqlCommand( _ "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection) ' Add the parameters for the DeleteCommand. command.Parameters.Add( _ "@CustomerID", SqlDbType.NChar, 5, "CustomerID") parameter.SourceVersion = DataRowVersion.Original adapter.DeleteCommand = command Return adapter End Function
public static SqlDataAdapter CreateCustomerAdapter( SqlConnection connection) { SqlDataAdapter adapter = new SqlDataAdapter(); // Create the SelectCommand. SqlCommand command = new SqlCommand("SELECT * FROM Customers " + "WHERE Country = @Country AND City = @City", connection); // Add the parameters for the SelectCommand. command.Parameters.Add("@Country", SqlDbType.NVarChar, 15); command.Parameters.Add("@City", SqlDbType.NVarChar, 15); adapter.SelectCommand = command; // Create the InsertCommand. command = new SqlCommand( "INSERT INTO Customers (CustomerID, CompanyName) " + "VALUES (@CustomerID, @CompanyName)", connection); // Add the parameters for the InsertCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID"); command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName"); adapter.InsertCommand = command; // Create the UpdateCommand. command = new SqlCommand( "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " + "WHERE CustomerID = @oldCustomerID", connection); // Add the parameters for the UpdateCommand. command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID"); command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName"); SqlParameter parameter = command.Parameters.Add( "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID"); parameter.SourceVersion = DataRowVersion.Original; adapter.UpdateCommand = command; // Create the DeleteCommand. command = new SqlCommand( "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection); // Add the parameters for the DeleteCommand. parameter = command.Parameters.Add( "@CustomerID", SqlDbType.NChar, 5, "CustomerID"); parameter.SourceVersion = DataRowVersion.Original; adapter.DeleteCommand = command; return adapter; }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からSqlDataAdapter.UpdateCommand プロパティを検索する場合は、下記のリンクをクリックしてください。

- SqlDataAdapter.UpdateCommand プロパティのページへのリンク