OleDbDataAdapter Construtores

Definição

Inicializa uma nova instância da classe OleDbDataAdapter.

Sobrecargas

OleDbDataAdapter()

Inicializa uma nova instância da classe OleDbDataAdapter.

OleDbDataAdapter(OleDbCommand)

Inicializa uma nova instância da classe OleDbDataAdapter com o OleDbCommand especificado como a propriedade SelectCommand.

OleDbDataAdapter(String, OleDbConnection)

Inicializa uma nova instância da classe OleDbDataAdapter com um SelectCommand.

OleDbDataAdapter(String, String)

Inicializa uma nova instância da classe OleDbDataAdapter com um SelectCommand.

OleDbDataAdapter()

Origem:
OleDbDataAdapter.cs
Origem:
OleDbDataAdapter.cs

Inicializa uma nova instância da classe OleDbDataAdapter.

public:
 OleDbDataAdapter();
public OleDbDataAdapter ();
Public Sub New ()

Exemplos

O exemplo a seguir cria um OleDbDataAdapter e define algumas de suas propriedades.

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

Comentários

Quando você cria uma instância do , as propriedades de OleDbDataAdapterleitura/gravação a seguir são definidas com os seguintes valores iniciais.

Propriedades Valor inicial
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Você pode alterar o valor de qualquer uma dessas propriedades por meio de uma chamada separada para a propriedade .

Confira também

Aplica-se a

OleDbDataAdapter(OleDbCommand)

Origem:
OleDbDataAdapter.cs
Origem:
OleDbDataAdapter.cs

Inicializa uma nova instância da classe OleDbDataAdapter com o OleDbCommand especificado como a propriedade 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

Um OleDbCommand que é uma instrução SELECT ou um procedimento armazenado e é definido como a propriedade SelectCommand do OleDbDataAdapter.

Exemplos

O exemplo a seguir cria um OleDbDataAdapter e define algumas de suas propriedades.

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

Comentários

Essa implementação do OleDbDataAdapter construtor define a SelectCommand propriedade como o valor especificado no selectCommand parâmetro .

Quando você cria uma instância do , as propriedades de OleDbDataAdapterleitura/gravação a seguir são definidas com os seguintes valores iniciais.

Propriedades Valor inicial
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Você pode alterar o valor de qualquer uma dessas propriedades por meio de uma chamada separada para a propriedade .

Confira também

Aplica-se a

OleDbDataAdapter(String, OleDbConnection)

Origem:
OleDbDataAdapter.cs
Origem:
OleDbDataAdapter.cs

Inicializa uma nova instância da classe OleDbDataAdapter com um 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

Uma cadeia de caracteres que é uma instrução SQL SELECT ou um procedimento armazenado a ser usado pela propriedade de SelectCommand do OleDbDataAdapter.

selectConnection
OleDbConnection

Um OleDbConnection que representa a conexão.

Exemplos

O exemplo a seguir cria um OleDbDataAdapter e define algumas de suas propriedades.

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

Comentários

Essa implementação do OleDbDataAdapter abre e fecha um OleDbConnection caso ainda não esteja aberto. Isso pode ser útil em um aplicativo que deve chamar o Fill método para dois ou mais OleDbDataAdapter objetos. Se o OleDbConnection já estiver aberto, você deverá chamar Close ou descartar explicitamente para fechá-lo.

Quando você cria uma instância do , as propriedades de OleDbDataAdapterleitura/gravação a seguir são definidas com os seguintes valores iniciais.

Propriedades Valor inicial
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Você pode alterar o valor de qualquer uma dessas propriedades por meio de uma chamada separada para a propriedade .

Confira também

Aplica-se a

OleDbDataAdapter(String, String)

Origem:
OleDbDataAdapter.cs
Origem:
OleDbDataAdapter.cs

Inicializa uma nova instância da classe OleDbDataAdapter com um 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

Uma cadeia de caracteres que é uma instrução SQL SELECT ou um procedimento armazenado a ser usado pela propriedade de SelectCommand do OleDbDataAdapter.

selectConnectionString
String

A cadeia de conexão.

Exemplos

O exemplo a seguir cria um OleDbDataAdapter e define algumas de suas propriedades.

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

Comentários

Essa sobrecarga do OleDbDataAdapter construtor usa o selectConnectionString parâmetro para definir a SelectCommand propriedade . No entanto, ele não abre a conexão. Você ainda deve abrir explicitamente a conexão.

Quando você cria uma instância do , as propriedades de OleDbDataAdapterleitura/gravação a seguir são definidas com os seguintes valores iniciais.

Propriedades Valor inicial
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Você pode alterar o valor de qualquer uma dessas propriedades por meio de uma chamada separada para a propriedade .

Confira também

Aplica-se a