Export (0) Print
Expand All

IDbDataAdapter.DeleteCommand Property

Gets or sets an SQL statement for deleting records from the data set.

[Visual Basic]
Property DeleteCommand As IDbCommand
[C#]
IDbCommand DeleteCommand {get; set;}
[C++]
__property IDbCommand* get_DeleteCommand();
__property void set_DeleteCommand(IDbCommand*);
[JScript]
function get DeleteCommand() : IDbCommand;function set DeleteCommand(IDbCommand);

Property Value

An IDbCommand used during Update to delete records in the data source for deleted rows in the data set.

Remarks

During Update, if this property is not set and primary key information is present in the DataSet, the DeleteCommand can be generated automatically if you set the SelectCommand property of a .NET Framework data provider. Then, any additional commands that you do not set are generated by the CommandBuilder. This generation logic requires key column information to be present in the DataSet. For more information see Automatically Generated Commands.

When DeleteCommand is assigned to a previously created IDbCommand, the IDbCommand is not cloned. The DeleteCommand maintains a reference to the previously created IDbCommand object.

Example

[Visual Basic, C#, C++] The following example creates an instance of the inherited OleDbDataAdapter class, and sets the SelectCommand and DeleteCommand properties. It assumes you have already created an OleDbConnection object.

[Visual Basic] 
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 DeleteCommand.

  cmd = New OleDbCommand("DELETE FROM Customers WHERE CustomerID = @CustomerID", conn)

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

  da.DeleteCommand = cmd

  Return da
End Function

[C#] 
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 DeleteCommand.

  cmd = new OleDbCommand("DELETE FROM Customers WHERE CustomerID = @CustomerID", conn);

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

  da.DeleteCommand = cmd;

  return da;
}

[C++] 
public:
static OleDbDataAdapter* CreateCustomerAdapter(OleDbConnection* conn)
{
  OleDbDataAdapter* da = new OleDbDataAdapter();
  OleDbCommand* cmd;
  OleDbParameter* parm;

  // Create the SelectCommand.

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

  cmd->Parameters->Add(S"@Country", OleDbType::VarChar, 15);
  cmd->Parameters->Add(S"@City", OleDbType::VarChar, 15);

  da->SelectCommand = cmd;

  // Create the DeleteCommand.

  cmd = new OleDbCommand(S"DELETE FROM Customers WHERE CustomerID = @CustomerID", conn);

  parm = cmd->Parameters->Add(S"@CustomerID", OleDbType::Char, 5, S"CustomerID");
  parm->SourceVersion = DataRowVersion::Original;

  da->DeleteCommand = cmd;

  return da;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

IDbDataAdapter Interface | IDbDataAdapter Members | System.Data Namespace

Show:
© 2014 Microsoft