System.Data.SqlClient Namespace SqlDataAdapter Class
Sets or retrieves a command to delete records from the data set.
[ VB ]
Public Property DeleteCommand As SqlCommand
[ C# ]
public SqlCommand DeleteCommand {get; set;}
[ C++ ]
public: __property SqlCommand* get_DeleteCommand ( );
public: __property void set_DeleteCommand ( SqlCommand* );
[ JScript ]
public function get DeleteCommand ( ) : SqlCommand;
public function set DeleteCommand ( SqlCommand );
An SqlCommand used during Update to delete records in the data source that correspond to deleted rows in the DataSet.
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 and use the SqlCommandBuilder. Then, any additional commands that you do not set are generated by the SqlCommandBuilder. 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 SqlCommand, the SqlCommand is not cloned. The DeleteCommand maintains a reference to the previously created SqlCommand object.
The following example illustrates use of the DeleteCommand property.
void DeleteCommandDemo ( ) {
string query = "SELECT * FROM Categories ";
string connString = "uid=sa; pwd=; database=northwind; server=myServer";
SqlDataAdapter myAdapter = new SqlDataAdapter ( query, connString );
myAdapter.DeleteCommand.CommandText =
"DELETE FROM Categories WHERE Category = 'Produce'";
myAdapter.DeleteCommand.Connection =
( SqlConnection ) myAdapter.SelectCommand.Connection.Clone ( );
}
public sub DeleteCommandDemo ( )
dim query as string = "SELECT * FROM Categories "
dim connString as string = "uid=sa; pwd=; database=northwind; server=myServer"
dim myAdapter as new SqlDataAdapter ( query, connString )
myAdapter.DeleteCommand.CommandText = _
"DELETE FROM Categories WHERE Category = 'Produce'"
myAdapter.DeleteCommand.Connection = Ctype (
myAdapter.SelectCommand.Connection.Clone ( ), SqlConnection );
end sub |
|
C# |
VB |
SqlDataAdapter Members InsertCommand SelectCommand UpdateCommand