System.Data.SqlClient Namespace SqlDataAdapter Class
Sets or retrieves a command used to update records in the data source.
[ VB ]
Public Property UpdateCommand As SqlCommand
[ C# ]
public SqlCommand UpdateCommand {get; set;}
[ C++ ]
public: __property SqlCommand* get_UpdateCommand ( );
public: __property void set_UpdateCommand ( SqlCommand* );
[ JScript ]
public function get UpdateCommand ( ) : SqlCommand;
public function set UpdateCommand ( SqlCommand );
An SqlCommand used during Update to update records in the data source that correspond to modified rows in the DataSet.
During Update, if this property is not set and primary key information is present in the DataSet, the UpdateCommand 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 UpdateCommand is assigned to a previously created SqlCommand, the SqlCommand is not cloned. The UpdateCommand maintains a reference to the previously created SqlCommand object.
NOTE: If execution of this command returns rows, the updated rows may be merged with the DataSet depending on how you set the UpdatedRowSource property of the SqlCommand object.
The following example illustrates use of the UpdateCommand property.
void UpdateCommandDemo ( ) {
string query = "SELECT * FROM Categories ";
string connString = "uid=sa; pwd=; database=northwind; server=myServer";
SqlDataAdapter myAdapter = new SqlDataAdapter ( query, connString );
myAdapter.UpdateCommand.CommandText =
"UPDATE Categories SET Description = 'Cheeses, Milk, Ice Cream' " +
"WHERE Category = 'Dairy Products'";
myAdapter.UpdateCommand.Connection =
( SqlConnection ) myAdapter.SelectCommand.Connection.Clone ( );
}
public sub UpdateCommandDemo ( )
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.UpdateCommand.CommandText = _
"UPDATE Categories SET Description = 'Cheeses, Milk, Ice Cream' " &_
"WHERE Category = 'Dairy Products'"
myAdapter.UpdateCommand.Connection = CType ( _
myAdapter.SelectCommand.Connection.Clone ( ), SqlConnection )
end sub |
|
C# |
VB |
SqlDataAdapter Members DeleteCommand InsertCommand SelectCommand