OleDbDataAdapter Constructores
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í.
Inicializa una nueva instancia de la clase OleDbDataAdapter.
Sobrecargas
OleDbDataAdapter() |
Inicializa una nueva instancia de la clase OleDbDataAdapter. |
OleDbDataAdapter(OleDbCommand) |
Inicializa una nueva instancia de la clase OleDbDataAdapter con el objeto OleDbCommand especificado como propiedad SelectCommand. |
OleDbDataAdapter(String, OleDbConnection) |
Inicializa una nueva instancia de la clase OleDbDataAdapter con la propiedad SelectCommand. |
OleDbDataAdapter(String, String) |
Inicializa una nueva instancia de la clase OleDbDataAdapter con la propiedad SelectCommand. |
OleDbDataAdapter()
- Source:
- OleDbDataAdapter.cs
- Source:
- OleDbDataAdapter.cs
Inicializa una nueva instancia de la clase OleDbDataAdapter.
public:
OleDbDataAdapter();
public OleDbDataAdapter ();
Public Sub New ()
Ejemplos
En el ejemplo siguiente se crea y OleDbDataAdapter se establecen algunas de sus propiedades.
public static OleDbDataAdapter CreateDataAdapter(
OleDbConnection connection)
{
string selectCommand =
"SELECT CustomerID, CompanyName FROM Customers";
OleDbDataAdapter adapter =
new OleDbDataAdapter(selectCommand, connection);
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create the Insert, Update and Delete commands.
adapter.InsertCommand = new OleDbCommand(
"INSERT INTO Customers (CustomerID, CompanyName) " +
"VALUES (?, ?)");
adapter.UpdateCommand = new OleDbCommand(
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
"WHERE CustomerID = ?");
adapter.DeleteCommand = new OleDbCommand(
"DELETE FROM Customers WHERE CustomerID = ?");
// Create the parameters.
adapter.InsertCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.InsertCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.UpdateCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
adapter.DeleteCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
return adapter;
}
Public Function CreateDataAdapter( _
ByVal connection As OleDbConnection) As OleDbDataAdapter
Dim selectCommand As String = _
"SELECT CustomerID, CompanyName FROM Customers"
Dim adapter As OleDbDataAdapter = _
New OleDbDataAdapter(selectCommand, connection)
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
' Create the commands.
adapter.InsertCommand = New OleDbCommand( _
"INSERT INTO Customers (CustomerID, CompanyName) " & _
"VALUES (?, ?)")
adapter.UpdateCommand = New OleDbCommand( _
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
"WHERE CustomerID = ?")
adapter.DeleteCommand = New OleDbCommand( _
"DELETE FROM Customers WHERE CustomerID = ?")
' Create the parameters.
adapter.InsertCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.InsertCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.UpdateCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
adapter.DeleteCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
Return adapter
End Function
Comentarios
Al crear una instancia de , las siguientes propiedades de OleDbDataAdapterlectura y escritura se establecen en los siguientes valores iniciales.
Propiedades | Valor inicial |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Puede cambiar el valor de cualquiera de estas propiedades a través de una llamada independiente a la propiedad .
Consulte también
Se aplica a
OleDbDataAdapter(OleDbCommand)
- Source:
- OleDbDataAdapter.cs
- Source:
- OleDbDataAdapter.cs
Inicializa una nueva instancia de la clase OleDbDataAdapter con el objeto OleDbCommand especificado como propiedad SelectCommand.
public:
OleDbDataAdapter(System::Data::OleDb::OleDbCommand ^ selectCommand);
public OleDbDataAdapter (System.Data.OleDb.OleDbCommand? selectCommand);
public OleDbDataAdapter (System.Data.OleDb.OleDbCommand selectCommand);
new System.Data.OleDb.OleDbDataAdapter : System.Data.OleDb.OleDbCommand -> System.Data.OleDb.OleDbDataAdapter
Public Sub New (selectCommand As OleDbCommand)
Parámetros
- selectCommand
- OleDbCommand
OleDbCommand que es un procedimiento almacenado o una instrucción SELECT y que se establece como la propiedad SelectCommand de OleDbDataAdapter.
Ejemplos
En el ejemplo siguiente se crea y OleDbDataAdapter se establecen algunas de sus propiedades.
public static OleDbDataAdapter CreateDataAdapter(string selectCommand,
OleDbConnection connection)
{
OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, connection);
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create the Insert, Update and Delete commands.
adapter.InsertCommand = new OleDbCommand(
"INSERT INTO Customers (CustomerID, CompanyName) " +
"VALUES (?, ?)");
adapter.UpdateCommand = new OleDbCommand(
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
"WHERE CustomerID = ?");
adapter.DeleteCommand = new OleDbCommand(
"DELETE FROM Customers WHERE CustomerID = ?");
// Create the parameters.
adapter.InsertCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.InsertCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.UpdateCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
adapter.DeleteCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
return adapter;
}
Public Function CreateDataAdapter(ByVal selectCommand As String, _
ByVal connection As OleDbConnection) As OleDbDataAdapter
Dim adapter As OleDbDataAdapter = _
New OleDbDataAdapter(selectCommand, connection)
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
' Create the commands.
adapter.InsertCommand = New OleDbCommand( _
"INSERT INTO Customers (CustomerID, CompanyName) " & _
"VALUES (?, ?)")
adapter.UpdateCommand = New OleDbCommand( _
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
"WHERE CustomerID = ?")
adapter.DeleteCommand = New OleDbCommand( _
"DELETE FROM Customers WHERE CustomerID = ?")
' Create the parameters.
adapter.InsertCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.InsertCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.UpdateCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
adapter.DeleteCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
Return adapter
End Function
Comentarios
Esta implementación del OleDbDataAdapter constructor establece la SelectCommand propiedad en el valor especificado en el selectCommand
parámetro .
Al crear una instancia de , las siguientes propiedades de OleDbDataAdapterlectura y escritura se establecen en los siguientes valores iniciales.
Propiedades | Valor inicial |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Puede cambiar el valor de cualquiera de estas propiedades a través de una llamada independiente a la propiedad .
Consulte también
Se aplica a
OleDbDataAdapter(String, OleDbConnection)
- Source:
- OleDbDataAdapter.cs
- Source:
- OleDbDataAdapter.cs
Inicializa una nueva instancia de la clase OleDbDataAdapter con la propiedad SelectCommand.
public:
OleDbDataAdapter(System::String ^ selectCommandText, System::Data::OleDb::OleDbConnection ^ selectConnection);
public OleDbDataAdapter (string? selectCommandText, System.Data.OleDb.OleDbConnection? selectConnection);
public OleDbDataAdapter (string selectCommandText, System.Data.OleDb.OleDbConnection selectConnection);
new System.Data.OleDb.OleDbDataAdapter : string * System.Data.OleDb.OleDbConnection -> System.Data.OleDb.OleDbDataAdapter
Public Sub New (selectCommandText As String, selectConnection As OleDbConnection)
Parámetros
- selectCommandText
- String
Cadena que es una instrucción SQL SELECT o un procedimiento almacenado que debe utilizar la propiedad SelectCommand de OleDbDataAdapter.
- selectConnection
- OleDbConnection
OleDbConnection que representa la conexión.
Ejemplos
En el ejemplo siguiente se crea y OleDbDataAdapter se establecen algunas de sus propiedades.
public static OleDbDataAdapter CreateDataAdapter(
OleDbConnection connection)
{
string selectCommand =
"SELECT CustomerID, CompanyName FROM Customers";
OleDbDataAdapter adapter =
new OleDbDataAdapter(selectCommand, connection);
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create the Insert, Update and Delete commands.
adapter.InsertCommand = new OleDbCommand(
"INSERT INTO Customers (CustomerID, CompanyName) " +
"VALUES (?, ?)");
adapter.UpdateCommand = new OleDbCommand(
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
"WHERE CustomerID = ?");
adapter.DeleteCommand = new OleDbCommand(
"DELETE FROM Customers WHERE CustomerID = ?");
// Create the parameters.
adapter.InsertCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.InsertCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.UpdateCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
adapter.DeleteCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
return adapter;
}
Public Function CreateDataAdapter( _
ByVal connection As OleDbConnection) As OleDbDataAdapter
Dim selectCommand As String = _
"SELECT CustomerID, CompanyName FROM Customers"
Dim adapter As OleDbDataAdapter = _
New OleDbDataAdapter(selectCommand, connection)
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
' Create the commands.
adapter.InsertCommand = New OleDbCommand( _
"INSERT INTO Customers (CustomerID, CompanyName) " & _
"VALUES (?, ?)")
adapter.UpdateCommand = New OleDbCommand( _
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
"WHERE CustomerID = ?")
adapter.DeleteCommand = New OleDbCommand( _
"DELETE FROM Customers WHERE CustomerID = ?")
' Create the parameters.
adapter.InsertCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.InsertCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.UpdateCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
adapter.DeleteCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
Return adapter
End Function
Comentarios
Esta implementación de OleDbDataAdapter se abre y cierra si OleDbConnection aún no está abierta. Esto puede ser útil en una aplicación que debe llamar al Fill método para dos o más OleDbDataAdapter objetos. Si ya OleDbConnection está abierto, debe llamar Close explícitamente a o Dispose para cerrarlo.
Al crear una instancia de , las siguientes propiedades de OleDbDataAdapterlectura y escritura se establecen en los siguientes valores iniciales.
Propiedades | Valor inicial |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Puede cambiar el valor de cualquiera de estas propiedades a través de una llamada independiente a la propiedad .
Consulte también
Se aplica a
OleDbDataAdapter(String, String)
- Source:
- OleDbDataAdapter.cs
- Source:
- OleDbDataAdapter.cs
Inicializa una nueva instancia de la clase OleDbDataAdapter con la propiedad SelectCommand.
public:
OleDbDataAdapter(System::String ^ selectCommandText, System::String ^ selectConnectionString);
public OleDbDataAdapter (string? selectCommandText, string? selectConnectionString);
public OleDbDataAdapter (string selectCommandText, string selectConnectionString);
new System.Data.OleDb.OleDbDataAdapter : string * string -> System.Data.OleDb.OleDbDataAdapter
Public Sub New (selectCommandText As String, selectConnectionString As String)
Parámetros
- selectCommandText
- String
Cadena que es una instrucción SQL SELECT o un procedimiento almacenado que debe utilizar la propiedad SelectCommand de OleDbDataAdapter.
- selectConnectionString
- String
La cadena de conexión.
Ejemplos
En el ejemplo siguiente se crea y OleDbDataAdapter se establecen algunas de sus propiedades.
public static OleDbDataAdapter CreateDataAdapter(
OleDbConnection connection)
{
string selectCommand =
"SELECT CustomerID, CompanyName FROM Customers";
OleDbDataAdapter adapter =
new OleDbDataAdapter(selectCommand, connection);
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create the Insert, Update and Delete commands.
adapter.InsertCommand = new OleDbCommand(
"INSERT INTO Customers (CustomerID, CompanyName) " +
"VALUES (?, ?)");
adapter.UpdateCommand = new OleDbCommand(
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
"WHERE CustomerID = ?");
adapter.DeleteCommand = new OleDbCommand(
"DELETE FROM Customers WHERE CustomerID = ?");
// Create the parameters.
adapter.InsertCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.InsertCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID");
adapter.UpdateCommand.Parameters.Add("@CompanyName",
OleDbType.VarChar, 40, "CompanyName");
adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
adapter.DeleteCommand.Parameters.Add("@CustomerID",
OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original;
return adapter;
}
Public Function CreateDataAdapter( _
ByVal connection As OleDbConnection) As OleDbDataAdapter
Dim selectCommand As String = _
"SELECT CustomerID, CompanyName FROM Customers"
Dim adapter As OleDbDataAdapter = _
New OleDbDataAdapter(selectCommand, connection)
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
' Create the commands.
adapter.InsertCommand = New OleDbCommand( _
"INSERT INTO Customers (CustomerID, CompanyName) " & _
"VALUES (?, ?)")
adapter.UpdateCommand = New OleDbCommand( _
"UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
"WHERE CustomerID = ?")
adapter.DeleteCommand = New OleDbCommand( _
"DELETE FROM Customers WHERE CustomerID = ?")
' Create the parameters.
adapter.InsertCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.InsertCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID")
adapter.UpdateCommand.Parameters.Add( _
"@CompanyName", OleDbType.VarChar, 40, "CompanyName")
adapter.UpdateCommand.Parameters.Add( _
"@oldCustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
adapter.DeleteCommand.Parameters.Add( _
"@CustomerID", OleDbType.Char, 5, "CustomerID").SourceVersion = _
DataRowVersion.Original
Return adapter
End Function
Comentarios
Esta sobrecarga del OleDbDataAdapter constructor usa el selectConnectionString
parámetro para establecer la SelectCommand propiedad . Sin embargo, no abre la conexión. Todavía debe abrir explícitamente la conexión.
Al crear una instancia de , las siguientes propiedades de OleDbDataAdapterlectura y escritura se establecen en los siguientes valores iniciales.
Propiedades | Valor inicial |
---|---|
MissingMappingAction | MissingMappingAction.Passthrough |
MissingSchemaAction | MissingSchemaAction.Add |
Puede cambiar el valor de cualquiera de estas propiedades a través de una llamada independiente a la propiedad .