OleDbDataAdapter Costruttori

Definizione

Inizializza una nuova istanza della classe OleDbDataAdapter.

Overload

OleDbDataAdapter()

Inizializza una nuova istanza della classe OleDbDataAdapter.

OleDbDataAdapter(OleDbCommand)

Inizializza una nuova istanza della classe OleDbDataAdapter con l'oggetto OleDbCommand specificato come la proprietà SelectCommand.

OleDbDataAdapter(String, OleDbConnection)

Inizializza una nuova istanza della classe OleDbDataAdapter con una proprietà SelectCommand.

OleDbDataAdapter(String, String)

Inizializza una nuova istanza della classe OleDbDataAdapter con una proprietà SelectCommand.

OleDbDataAdapter()

Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs

Inizializza una nuova istanza della classe OleDbDataAdapter.

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

Esempio

Nell'esempio seguente viene creato un oggetto OleDbDataAdapter e vengono impostate alcune delle relative proprietà.

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

Commenti

Quando si crea un'istanza di , le proprietà di OleDbDataAdapterlettura/scrittura seguenti vengono impostate sui valori iniziali seguenti.

Proprietà Valore iniziale
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

È possibile modificare il valore di una di queste proprietà tramite una chiamata separata alla proprietà .

Vedi anche

Si applica a

OleDbDataAdapter(OleDbCommand)

Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs

Inizializza una nuova istanza della classe OleDbDataAdapter con l'oggetto OleDbCommand specificato come la proprietà 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)

Parametri

selectCommand
OleDbCommand

Oggetto OleDbCommand che è un'istruzione SELECT o una stored procedure, impostato come la proprietà SelectCommand dell'oggetto OleDbDataAdapter .

Esempio

Nell'esempio seguente viene creato un oggetto OleDbDataAdapter e vengono impostate alcune delle relative proprietà.

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

Commenti

Questa implementazione del OleDbDataAdapter costruttore imposta la SelectCommand proprietà sul valore specificato nel selectCommand parametro .

Quando si crea un'istanza di , le proprietà di OleDbDataAdapterlettura/scrittura seguenti vengono impostate sui valori iniziali seguenti.

Proprietà Valore iniziale
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

È possibile modificare il valore di una di queste proprietà tramite una chiamata separata alla proprietà .

Vedi anche

Si applica a

OleDbDataAdapter(String, OleDbConnection)

Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs

Inizializza una nuova istanza della classe OleDbDataAdapter con una proprietà 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)

Parametri

selectCommandText
String

Stringa che è un'istruzione SQL SELECT o una stored procedure, utilizzata dalla proprietà SelectCommand della classe OleDbDataAdapter.

selectConnection
OleDbConnection

Classe OleDbConnection che rappresenta la connessione.

Esempio

Nell'esempio seguente viene creato un oggetto OleDbDataAdapter e vengono impostate alcune delle relative proprietà.

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

Commenti

Questa implementazione di OleDbDataAdapter apre e chiude un OleDbConnection oggetto se non è già aperto. Ciò può essere utile in un'applicazione che deve chiamare il Fill metodo per due o più OleDbDataAdapter oggetti. Se è OleDbConnection già aperto, è necessario chiamare Close in modo esplicito o Dispose per chiuderlo.

Quando si crea un'istanza di , le proprietà di OleDbDataAdapterlettura/scrittura seguenti vengono impostate sui valori iniziali seguenti.

Proprietà Valore iniziale
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

È possibile modificare il valore di una di queste proprietà tramite una chiamata separata alla proprietà .

Vedi anche

Si applica a

OleDbDataAdapter(String, String)

Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs
Origine:
OleDbDataAdapter.cs

Inizializza una nuova istanza della classe OleDbDataAdapter con una proprietà 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)

Parametri

selectCommandText
String

Stringa che è un'istruzione SQL SELECT o una stored procedure, utilizzata dalla proprietà SelectCommand della classe OleDbDataAdapter.

selectConnectionString
String

Stringa di connessione.

Esempio

Nell'esempio seguente viene creato un oggetto OleDbDataAdapter e vengono impostate alcune delle relative proprietà.

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

Commenti

Questo overload del OleDbDataAdapter costruttore usa il selectConnectionString parametro per impostare la SelectCommand proprietà . Tuttavia, non apre la connessione. È comunque necessario aprire in modo esplicito la connessione.

Quando si crea un'istanza di , le proprietà di OleDbDataAdapterlettura/scrittura seguenti vengono impostate sui valori iniziali seguenti.

Proprietà Valore iniziale
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

È possibile modificare il valore di una di queste proprietà tramite una chiamata separata alla proprietà .

Vedi anche

Si applica a