DbDataAdapter.UpdateCommand Property

 

Gets or sets a command used to update records in the data source.

Namespace:   System.Data.Common
Assembly:  System.Data (in System.Data.dll)

[BrowsableAttribute(false)]
public DbCommand UpdateCommand { get; set; }

Property Value

Type: System.Data.Common.DbCommand

A IDbCommand used during Update to update records in the data source for modified rows in the data set.

During Update, if this property is not set and primary key information is present in the DataSet, the UpdateCommand will be automatically generated.

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;
}

.NET Framework
Available since 2.0
Return to top
Show: