MySQL Connector/Net |
MySqlDataAdapter..::.UpdateCommand Property |
MySqlDataAdapter Class Example See Also Send Feedback |
Gets or sets a SQL statement or stored procedure used to updated records in the data source.
Namespace:
MySql.Data.MySqlClient
Assembly:
MySql.Data (in MySql.Data.dll) Version: 6.2.2.0
Syntax
C# |
---|
public MySqlCommand UpdateCommand { get; set; } |
Visual Basic (Declaration) |
---|
Public Property UpdateCommand As MySqlCommand |
Visual C++ |
---|
public: property MySqlCommand^ UpdateCommand { MySqlCommand^ get (); void set (MySqlCommand^ value); } |
Field Value
A MySqlCommand used during Update(DataSet) to update records in the database with data from the DataSet.Remarks
During Update(DataSet), 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 MySqlCommandBuilder. Then, any additional commands that you do not set are generated by the MySqlCommandBuilder. This generation logic requires key column information to be present in the DataSet.
When UpdateCommand is assigned to a previously created MySqlCommand, the MySqlCommand is not cloned. The UpdateCommand maintains a reference to the previously created MySqlCommand object.
Note:
If execution of this command returns rows, these rows may be merged with the DataSet
depending on how you set the UpdatedRowSource property of the MySqlCommand object.
Examples
The following example creates a MySqlDataAdapter and sets the
SelectCommand and UpdateCommand properties. It assumes you have already
created a MySqlConnection object.
CopyVB.NET
Public Shared Function CreateCustomerAdapter(conn As MySqlConnection) As MySqlDataAdapter Dim da As MySqlDataAdapter = New MySqlDataAdapter() Dim cmd As MySqlCommand Dim parm As MySqlParameter ' Create the SelectCommand. cmd = New MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn) cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15) cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15) da.SelectCommand = cmd ' Create the UpdateCommand. cmd = New MySqlCommand("UPDATE mytable SET id=@id, name=@name WHERE id=@oldId", conn) cmd.Parameters.Add( "@id", MySqlDbType.VarChar, 15, "id" ) cmd.Parameters.Add( "@name", MySqlDbType.VarChar, 15, "name" ) parm = cmd.Parameters.Add("@oldId", MySqlDbType.VarChar, 15, "id") parm.SourceVersion = DataRowVersion.Original da.UpdateCommand = cmd Return da End Function
CopyC#
public static MySqlDataAdapter CreateCustomerAdapter(MySqlConnection conn) { MySqlDataAdapter da = new MySqlDataAdapter(); MySqlCommand cmd; MySqlParameter parm; // Create the SelectCommand. cmd = new MySqlCommand("SELECT * FROM mytable WHERE id=@id AND name=@name", conn); cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15); cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15); da.SelectCommand = cmd; // Create the UpdateCommand. cmd = new MySqlCommand("UPDATE mytable SET id=@id, name=@name WHERE id=@oldId", conn); cmd.Parameters.Add("@id", MySqlDbType.VarChar, 15, "id" ); cmd.Parameters.Add("@name", MySqlDbType.VarChar, 15, "name" ); parm = cmd.Parameters.Add( "@oldId", MySqlDbType.VarChar, 15, "id" ); parm.SourceVersion = DataRowVersion.Original; da.UpdateCommand = cmd; return da; }