共用方式為


DbDataAdapter.UpdateCommand 屬性

定義

取得或設定用來在資料來源中更新資料錄的命令。

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; }
[System.ComponentModel.Browsable(false)]
public System.Data.Common.DbCommand UpdateCommand { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.UpdateCommand : System.Data.Common.DbCommand with get, set
Public Property UpdateCommand As DbCommand

屬性值

IDbCommand,在 Update(DataSet) 期間用來為資料集中修改的資料列更新在資料來源中的資料錄。

屬性

範例

下列範例會建立衍生類別 OleDbDataAdapter ,並設定其部分屬性。

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 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,如果未設定這個屬性,而且主鍵資訊存在於 中 DataSetUpdateCommand 則會自動產生 。

適用於

另請參閱