This documentation is archived and is not being maintained.

OdbcDataAdapter.DeleteCommand Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets or sets an SQL statement or stored procedure used to delete records in the data source.

[Visual Basic]
Public Shadows Property DeleteCommand As OdbcCommand
public new OdbcCommand DeleteCommand {get; set;}
public: __property OdbcCommand* get_DeleteCommand();
public: __property void set_DeleteCommand(OdbcCommand*);
public hide function get DeleteCommand() : OdbcCommand;
public function set DeleteCommand(OdbcCommand);

Property Value

An OdbcCommand used during an update operation to delete records in the data source that correspond to deleted rows in the DataSet.


When the DeleteCommand property is assigned to a previously created OdbcCommand, the OdbcCommand is not cloned. Instead, the DeleteCommand maintains a reference to the previously created OdbcCommand.

During an update operation, if DeleteCommand is not set and primary key information is present in the DataSet, you can use the OdbcCommandBuilder class to automatically generate the DeleteCommand, and additional commands needed to reconcile the DataSet to the data source. To do this, set the SelectCommand property of the the OdbcDataAdapter. The generation logic also requires key column information to be present in the DataSet. For more information see Automatically Generated Commands.


[Visual Basic, C#, C++] The following example creates an OdbcDataAdapter and sets the SelectCommand and DeleteCommand properties. It assumes you have already created an OdbcConnection object.

[Visual Basic] 
Public Sub CreateOdbcDataAdapter()
    Dim mySelectText As String = _
       "SELECT * FROM Categories ORDER BY CategoryID"
    Dim myConnString As String = _
       "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;"
    Dim myDataAdapter As New OdbcDataAdapter(mySelectText, myConnString)
    myDataAdapter.DeleteCommand = New OdbcCommand("DELETE FROM Categories WHERE CategoryName=?", myDataAdapter.SelectCommand.Connection)
End Sub

public void CreateOdbcDataAdapter() 
   string mySelectText = "SELECT * FROM Categories ORDER BY CategoryID";
   string myConnString = "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
   OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(mySelectText,myConnString);
   myDataAdapter.DeleteCommand = new OdbcCommand("DELETE FROM Categories WHERE CategoryName=?",myDataAdapter.SelectCommand.Connection);

    void CreateOdbcDataAdapter()
        String* mySelectText = S"SELECT * FROM Categories ORDER BY CategoryID";
        String* myConnString = S"DRIVER= {SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
        OdbcDataAdapter* myDataAdapter = new OdbcDataAdapter(mySelectText, myConnString);
        myDataAdapter->DeleteCommand = new OdbcCommand(S"DELETE FROM Categories WHERE CategoryName='Produce'", myDataAdapter->SelectCommand->Connection);

[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.


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

See Also

OdbcDataAdapter Class | OdbcDataAdapter Members | System.Data.Odbc Namespace | InsertCommand | SelectCommand | UpdateCommand