OleDbDataAdapter.InsertCommand Propriété

Définition

Récupère ou définit une instruction SQL ou une procédure stockée utilisée pour insérer de nouveaux enregistrements dans la source de données.

public:
 property System::Data::OleDb::OleDbCommand ^ InsertCommand { System::Data::OleDb::OleDbCommand ^ get(); void set(System::Data::OleDb::OleDbCommand ^ value); };
public System.Data.OleDb.OleDbCommand InsertCommand { get; set; }
public System.Data.OleDb.OleDbCommand? InsertCommand { get; set; }
[System.Data.DataSysDescription("DbDataAdapter_InsertCommand")]
public System.Data.OleDb.OleDbCommand InsertCommand { get; set; }
member this.InsertCommand : System.Data.OleDb.OleDbCommand with get, set
[<System.Data.DataSysDescription("DbDataAdapter_InsertCommand")>]
member this.InsertCommand : System.Data.OleDb.OleDbCommand with get, set
Public Property InsertCommand As OleDbCommand

Valeur de propriété

OleDbCommand utilisé pendant la mise à jour (Update(DataSet)) pour insérer dans la source de données les enregistrements qui correspondent aux nouvelles lignes de DataSet.

Attributs

Exemples

L’exemple suivant crée un OleDbDataAdapter et définit les SelectCommand propriétés et InsertCommand . Il suppose que vous avez déjà créé un OleDbConnection objet.

public static OleDbDataAdapter CreateCustomerAdapter(
    OleDbConnection connection)
{
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    OleDbCommand command;

    // Create the SelectCommand.
    command = new OleDbCommand("SELECT CustomerID FROM Customers " +
        "WHERE Country = ? AND City = ?", connection);

    command.Parameters.Add("Country", OleDbType.VarChar, 15);
    command.Parameters.Add("City", OleDbType.VarChar, 15);

    adapter.SelectCommand = command;

    // Create the InsertCommand.
    command = new OleDbCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)", connection);

    command.Parameters.Add(
        "CustomerID", OleDbType.Char, 5, "CustomerID");
    command.Parameters.Add(
        "CompanyName", OleDbType.VarChar, 40, "CompanyName");

    adapter.InsertCommand = command;
    return adapter;
}
Public Shared Function CreateCustomerAdapter( _
    connection As OleDbConnection) As OleDbDataAdapter 
  
    Dim adapter As New OleDbDataAdapter()
    Dim command As OleDbCommand

    ' Create the SelectCommand.
    command = New OleDbCommand("SELECT CustomerID FROM Customers " & _
        "WHERE Country = ? AND City = ?", connection)

    command.Parameters.Add("Country", OleDbType.VarChar, 15)
    command.Parameters.Add("City", OleDbType.VarChar, 15)

    adapter.SelectCommand = command

    ' Create the InsertCommand.
    command = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
        "VALUES (?, ?)", connection)

    command.Parameters.Add( _
        "CustomerID", OleDbType.Char, 5, "CustomerID")
    command.Parameters.Add( _
        "CompanyName", OleDbType.VarChar, 40, "CompanyName")

    adapter.InsertCommand = command
    Return adapter
End Function

Remarques

Pendant Update, si cette propriété n’est pas définie et que des informations sur la clé primaire sont présentes dans , DataSetle InsertCommand peut être généré automatiquement si vous définissez la SelectCommand propriété et utilisez .OleDbCommandBuilder Ensuite, toutes les commandes supplémentaires que vous ne définissez pas sont générées par .OleDbCommandBuilder Cette logique de génération nécessite que les informations de colonne clés soient présentes dans .DataSet Pour plus d’informations, consultez Génération de commandes avec CommandBuilders.

Quand InsertCommand est affecté à un précédemment créé OleDbCommand, le n’est OleDbCommand pas cloné. conserve InsertCommand une référence à l’objet créé précédemment OleDbCommand .

Notes

Si l’exécution de cette commande retourne des lignes, ces lignes peuvent être ajoutées à la en fonction de la DataSet façon dont vous définissez la UpdatedRowSource propriété de l’objet OleDbCommand .

S’applique à

Voir aussi