IDbDataAdapter.UpdateCommand Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece una instrucción SQL que se usa para actualizar los registros del origen de datos.
public:
property System::Data::IDbCommand ^ UpdateCommand { System::Data::IDbCommand ^ get(); void set(System::Data::IDbCommand ^ value); };
public System.Data.IDbCommand UpdateCommand { get; set; }
member this.UpdateCommand : System.Data.IDbCommand with get, set
Public Property UpdateCommand As IDbCommand
Valor de propiedad
que IDbCommand se usa durante Update(DataSet) para actualizar los registros del origen de datos para las filas modificadas del conjunto de datos.
Ejemplos
En el ejemplo siguiente se crea una instancia de la clase heredada OleDbDataAdapter y se establecen las SelectCommand propiedades y UpdateCommand . Se supone que ya ha creado un OleDbConnection objeto .
private static OleDbDataAdapter CreateCustomerAdapter(
OleDbConnection connection)
{
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
OleDbCommand command;
OleDbParameter parameter;
// Create the SelectCommand.
command = new OleDbCommand("SELECT * FROM dbo.Customers " +
"WHERE Country = ? AND City = ?", connection);
command.Parameters.Add("Country", OleDbType.VarChar, 15);
command.Parameters.Add("City", OleDbType.VarChar, 15);
dataAdapter.SelectCommand = command;
// Create the UpdateCommand.
command = new OleDbCommand(
"UPDATE dbo.Customers SET CustomerID = ?, CompanyName = ? " +
"WHERE CustomerID = ?", connection);
command.Parameters.Add(
"CustomerID", OleDbType.Char, 5, "CustomerID");
command.Parameters.Add(
"CompanyName", OleDbType.VarChar, 40, "CompanyName");
parameter = command.Parameters.Add(
"oldCustomerID", OleDbType.Char, 5, "CustomerID");
parameter.SourceVersion = DataRowVersion.Original;
dataAdapter.UpdateCommand = command;
return dataAdapter;
}
Private Function CreateCustomerAdapter( _
ByVal connection As OleDbConnection) As OleDbDataAdapter
Dim dataAdapter As New OleDbDataAdapter()
Dim command As OleDbCommand
Dim parameter As OleDbParameter
' Create the SelectCommand.
command = New OleDbCommand("SELECT * FROM dbo.Customers " & _
"WHERE Country = ? AND City = ?", connection)
command.Parameters.Add("Country", OleDbType.VarChar, 15)
command.Parameters.Add("City", OleDbType.VarChar, 15)
dataAdapter.SelectCommand = command
' Create the UpdateCommand.
command = New OleDbCommand("UPDATE dbo.Customers " & _
"SET CustomerID = ?, CompanyName = ? " & _
"WHERE CustomerID = ?", connection)
command.Parameters.Add( _
"CustomerID", OleDbType.Char, 5, "CustomerID")
command.Parameters.Add( _
"CompanyName", OleDbType.VarChar, 40, "CompanyName")
parameter = command.Parameters.Add( _
"oldCustomerID", OleDbType.Char, 5, "CustomerID")
parameter.SourceVersion = DataRowVersion.Original
dataAdapter.UpdateCommand = command
Return dataAdapter
End Function
Comentarios
Durante Update, si esta propiedad no está establecida y la información de clave principal está presente en DataSet, UpdateCommand se puede generar automáticamente si establece la SelectCommand propiedad de un proveedor de datos de .NET Framework. A continuación, el CommandBuilder genera los comandos adicionales que no establezca. Esta lógica de generación requiere que la información de columna de clave esté presente en .DataSet Para obtener más información, vea Generar comandos con CommandBuilders.
Cuando UpdateCommand se asigna a un objeto creado IDbCommandanteriormente, no IDbCommand se clona. UpdateCommand mantiene una referencia al objeto creado IDbCommand anteriormente.
Note
Si la ejecución de este comando devuelve filas, estas filas se agregan a .DataSet