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

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 propriétés et InsertCommand les SelectCommand propriétés. 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 les informations de clé primaire sont présentes dans le DataSet, il InsertCommand peut être généré automatiquement si vous définissez la propriété et utilisez le SelectCommand OleDbCommandBuilder. Ensuite, toutes les commandes supplémentaires que vous ne définissez pas sont générées par le OleDbCommandBuilder. Cette logique de génération nécessite que les informations de colonne clés soient présentes dans le DataSet. Pour plus d’informations, consultez Génération de commandes avec CommandBuilders.

Lorsqu’il InsertCommand est affecté à un élément créé OleDbCommandprécédemment, il OleDbCommand n’est pas cloné. Le InsertCommand service gère une référence à l’objet créé OleDbCommand précédemment.

Notes

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

S’applique à

Voir aussi