SqlDataAdapter.UpdateCommand Property


Gets or sets a Transact-SQL statement or stored procedure used to update records in the data source.

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

member UpdateCommand : SqlCommand with get, set

Property Value

Type: System.Data.SqlClient.SqlCommand

A SqlCommand used during Update to update records in the database 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 Generating Commands with CommandBuilders.

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.


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.

For every column that you propagate to the data source on Update, a parameter should be added to InsertCommand, UpdateCommand, or DeleteCommand.

The SourceColumn property of the parameter should be set to the name of the column. This indicates that the value of the parameter is not set manually, but taken from the particular column in the currently processed row.

The following example creates a SqlDataAdapter and sets the SelectCommand, InsertCommand, UpdateCommand and DeleteCommand properties. It assumes you have already created a SqlConnection object.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top