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
Remarks
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
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
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;
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;
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;
}
See Also