OleDbDataAdapter Constructors

Definition

Initializes a new instance of the OleDbDataAdapter class.

Overloads

OleDbDataAdapter()

Initializes a new instance of the OleDbDataAdapter class.

OleDbDataAdapter(OleDbCommand)

Initializes a new instance of the OleDbDataAdapter class with the specified OleDbCommand as the SelectCommand property.

OleDbDataAdapter(String, OleDbConnection)

Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.

OleDbDataAdapter(String, String)

Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.

OleDbDataAdapter()

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

Initializes a new instance of the OleDbDataAdapter class.

C#
public OleDbDataAdapter();

Examples

The following example creates an OleDbDataAdapter and sets some of its properties.

C#
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;
}

Remarks

When you create an instance of OleDbDataAdapter, the following read/write properties are set to the following initial values.

Properties Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

You can change the value of any of these properties through a separate call to the property.

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

OleDbDataAdapter(OleDbCommand)

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

Initializes a new instance of the OleDbDataAdapter class with the specified OleDbCommand as the SelectCommand property.

C#
public OleDbDataAdapter(System.Data.OleDb.OleDbCommand? selectCommand);
C#
public OleDbDataAdapter(System.Data.OleDb.OleDbCommand selectCommand);

Parameters

selectCommand
OleDbCommand

An OleDbCommand that is a SELECT statement or stored procedure, and is set as the SelectCommand property of the OleDbDataAdapter.

Examples

The following example creates an OleDbDataAdapter and sets some of its properties.

C#
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;
}

Remarks

This implementation of the OleDbDataAdapter constructor sets the SelectCommand property to the value specified in the selectCommand parameter.

When you create an instance of OleDbDataAdapter, the following read/write properties are set to the following initial values.

Properties Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

You can change the value of any of these properties through a separate call to the property.

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

OleDbDataAdapter(String, OleDbConnection)

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.

C#
public OleDbDataAdapter(string? selectCommandText, System.Data.OleDb.OleDbConnection? selectConnection);
C#
public OleDbDataAdapter(string selectCommandText, System.Data.OleDb.OleDbConnection selectConnection);

Parameters

selectCommandText
String

A string that is an SQL SELECT statement or stored procedure to be used by the SelectCommand property of the OleDbDataAdapter.

selectConnection
OleDbConnection

An OleDbConnection that represents the connection.

Examples

The following example creates an OleDbDataAdapter and sets some of its properties.

C#
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;
}

Remarks

This implementation of the OleDbDataAdapter opens and closes an OleDbConnection if it is not already open. This can be useful in an application that must call the Fill method for two or more OleDbDataAdapter objects. If the OleDbConnection is already open, you must explicitly call Close or Dispose to close it.

When you create an instance of OleDbDataAdapter, the following read/write properties are set to the following initial values.

Properties Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

You can change the value of either of these properties through a separate call to the property.

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

OleDbDataAdapter(String, String)

Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs
Source:
OleDbDataAdapter.cs

Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.

C#
public OleDbDataAdapter(string? selectCommandText, string? selectConnectionString);
C#
public OleDbDataAdapter(string selectCommandText, string selectConnectionString);

Parameters

selectCommandText
String

A string that is an SQL SELECT statement or stored procedure to be used by the SelectCommand property of the OleDbDataAdapter.

selectConnectionString
String

The connection string.

Examples

The following example creates an OleDbDataAdapter and sets some of its properties.

C#
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;
}

Remarks

This overload of the OleDbDataAdapter constructor uses the selectConnectionString parameter to set the SelectCommand property. However, it does not open the connection. You still must explicitly open the connection.

When you create an instance of OleDbDataAdapter, the following read/write properties are set to the following initial values.

Properties Initial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

You can change the value of any of these properties through a separate call to the property.

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)