SqlDataAdapter.UpdateCommand プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlDataAdapter.UpdateCommand プロパティの意味・解説 

SqlDataAdapter.UpdateCommand プロパティ

データ ソース内のレコード更新するための Transact-SQL ステートメントまたはストアド プロシージャ取得または設定します

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

Public Property UpdateCommand As
 SqlCommand
Dim instance As SqlDataAdapter
Dim value As SqlCommand

value = instance.UpdateCommand

instance.UpdateCommand = value
public SqlCommand UpdateCommand { get; set;
 }
public:
property SqlCommand^ UpdateCommand {
    SqlCommand^ get ();
    void set (SqlCommand^ 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 内にキー情報存在している必要があります詳細については、「コマンド自動生成」を参照してください

作成済みSqlCommandUpdateCommand割り当てられ場合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;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からSqlDataAdapter.UpdateCommand プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からSqlDataAdapter.UpdateCommand プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からSqlDataAdapter.UpdateCommand プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SqlDataAdapter.UpdateCommand プロパティ」の関連用語

SqlDataAdapter.UpdateCommand プロパティのお隣キーワード
検索ランキング

   

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



SqlDataAdapter.UpdateCommand プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS