DbDataAdapter.UpdateCommand DbDataAdapter.UpdateCommand DbDataAdapter.UpdateCommand DbDataAdapter.UpdateCommand Property

定義

データ ソース内のレコードを更新するコマンドを取得または設定します。Gets or sets a command used to update records in the data source.

public:
 property System::Data::Common::DbCommand ^ UpdateCommand { System::Data::Common::DbCommand ^ get(); void set(System::Data::Common::DbCommand ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Data.Common.DbCommand UpdateCommand { get; set; }
member this.UpdateCommand : System.Data.Common.DbCommand with get, set
Public Property UpdateCommand As DbCommand

プロパティ値

データ セット内の変更された行に対応するデータ ソース内のレコードを更新するために、IDbCommand 中に使用する Update(DataSet)A IDbCommand used during Update(DataSet) to update records in the data source for modified rows in the data set.

次の例では、派生OleDbDataAdapterクラスを作成し、そのプロパティの一部を設定します。The following example creates the derived class OleDbDataAdapter and sets some of its properties.

public static OleDbDataAdapter CreateCustomerAdapter(OleDbConnection conn)
{
  OleDbDataAdapter da = new OleDbDataAdapter();
  OleDbCommand cmd;
  OleDbParameter parm;

  // Create the SelectCommand.

  cmd = new OleDbCommand("SELECT * FROM Customers " +
                       "WHERE Country = @Country AND City = @City", conn);

  cmd.Parameters.Add("@Country", OleDbType.VarChar, 15);
  cmd.Parameters.Add("@City", OleDbType.VarChar, 15);

  da.SelectCommand = cmd;

  // Create the UpdateCommand.

  cmd = new OleDbCommand("UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " +
                       "WHERE CustomerID = @oldCustomerID", conn);

  cmd.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID");
  cmd.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName");

  parm = cmd.Parameters.Add("@oldCustomerID", OleDbType.Char, 5, "CustomerID");
  parm.SourceVersion = DataRowVersion.Original;

  da.UpdateCommand = cmd;

  return da;
}
Public Shared Function CreateCustomerAdapter(conn As OleDbConnection) As OleDbDataAdapter 
  
  Dim da As OleDbDataAdapter = New OleDbDataAdapter()
  Dim cmd As OleDbCommand
  Dim parm As OleDbParameter

  ' Create the SelectCommand.

  cmd = New OleDbCommand("SELECT * FROM Customers " & _
                       "WHERE Country = @Country AND City = @City", conn)

  cmd.Parameters.Add("@Country", OleDbType.VarChar, 15)
  cmd.Parameters.Add("@City", OleDbType.VarChar, 15)

  da.SelectCommand = cmd

  ' Create the UpdateCommand.

  cmd = New OleDbCommand("UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " & _
                       "WHERE CustomerID = @oldCustomerID", conn)

  cmd.Parameters.Add("@CustomerID", OleDbType.Char, 5, "CustomerID")
  cmd.Parameters.Add("@CompanyName", OleDbType.VarChar, 40, "CompanyName")

  parm = cmd.Parameters.Add("@oldCustomerID", OleDbType.Char, 5, "CustomerID")
  parm.SourceVersion = DataRowVersion.Original

  da.UpdateCommand = cmd

  Return da
End Function

注釈

Update間、このプロパティが設定されておらず、 DataSetに主キー情報がUpdateCommand含まれている場合は、が自動的に生成されます。During Update, if this property is not set and primary key information is present in the DataSet, the UpdateCommand will be automatically generated.

適用対象

こちらもご覧ください