OdbcDataAdapter OdbcDataAdapter OdbcDataAdapter OdbcDataAdapter Constructors

Définition

Surcharges

OdbcDataAdapter() OdbcDataAdapter() OdbcDataAdapter()

Initialise une nouvelle instance de la classe OdbcDataAdapter.Initializes a new instance of the OdbcDataAdapter class.

OdbcDataAdapter(OdbcCommand) OdbcDataAdapter(OdbcCommand) OdbcDataAdapter(OdbcCommand) OdbcDataAdapter(OdbcCommand)

Initialise une nouvelle instance de la classe OdbcDataAdapter avec l'instruction SQL SELECT spécifiée.Initializes a new instance of the OdbcDataAdapter class with the specified SQL SELECT statement.

OdbcDataAdapter(String, OdbcConnection) OdbcDataAdapter(String, OdbcConnection) OdbcDataAdapter(String, OdbcConnection) OdbcDataAdapter(String, OdbcConnection)

Initialise une nouvelle instance de la classe OdbcDataAdapter avec une instruction SQL SELECT et OdbcConnection.Initializes a new instance of the OdbcDataAdapter class with an SQL SELECT statement and an OdbcConnection.

OdbcDataAdapter(String, String) OdbcDataAdapter(String, String) OdbcDataAdapter(String, String) OdbcDataAdapter(String, String)

Initialise une nouvelle instance de la classe OdbcDataAdapter avec une instruction SQL SELECT et une chaîne de connexion.Initializes a new instance of the OdbcDataAdapter class with an SQL SELECT statement and a connection string.

OdbcDataAdapter() OdbcDataAdapter() OdbcDataAdapter()

Initialise une nouvelle instance de la classe OdbcDataAdapter.Initializes a new instance of the OdbcDataAdapter class.

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

Exemples

L’exemple suivant crée un OdbcDataAdapter et définit certaines de ses propriétés.The following example creates an OdbcDataAdapter and sets some of its properties.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add( _
        "@oldCustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Remarques

Lorsque vous créez une instance de OdbcDataAdapter, les valeurs par défaut des propriétés en écriture seule et en lecture seule suivantes sont définies, comme indiqué dans le tableau.When you create an instance of OdbcDataAdapter, the following write-only and read-only properties are set to their default values, as shown in the table.

PropriétésProperties Valeur par défautDefault value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Vous pouvez modifier la valeur de l’une de ces propriétés via un appel séparé à la propriété.You can change the value of any of these properties through a separate call to the property.

Voir aussi

OdbcDataAdapter(OdbcCommand) OdbcDataAdapter(OdbcCommand) OdbcDataAdapter(OdbcCommand) OdbcDataAdapter(OdbcCommand)

Initialise une nouvelle instance de la classe OdbcDataAdapter avec l'instruction SQL SELECT spécifiée.Initializes a new instance of the OdbcDataAdapter class with the specified SQL SELECT statement.

public:
 OdbcDataAdapter(System::Data::Odbc::OdbcCommand ^ selectCommand);
public OdbcDataAdapter (System.Data.Odbc.OdbcCommand selectCommand);
new System.Data.Odbc.OdbcDataAdapter : System.Data.Odbc.OdbcCommand -> System.Data.Odbc.OdbcDataAdapter
Public Sub New (selectCommand As OdbcCommand)

Paramètres

selectCommand
OdbcCommand OdbcCommand OdbcCommand OdbcCommand

OdbcCommand qui est une instruction SQL SELECT ou une procédure stockée définie en tant que propriété SelectCommand de OdbcDataAdapter.An OdbcCommand that is an SQL SELECT statement or stored procedure, and is set as the SelectCommand property of the OdbcDataAdapter.

Exemples

L’exemple suivant crée un OdbcDataAdapter et définit certaines de ses propriétés.The following example creates an OdbcDataAdapter and sets some of its properties.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add( _
        "@oldCustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Remarques

Cette implémentation du OdbcDataAdapter constructeur affecte à la SelectCommand propriété la valeur spécifiée dans le selectCommand paramètre.This implementation of the OdbcDataAdapter constructor sets the SelectCommand property to the value specified in the selectCommand parameter.

Lorsque vous créez une instance de OdbcDataAdapter, les valeurs par défaut des propriétés en écriture seule et en lecture seule suivantes sont définies, comme indiqué dans le tableau.When you create an instance of OdbcDataAdapter, the following write-only and read-only properties are set to their default values, as shown in the table.

PropriétésProperties Valeur initialeInitial value
MissingMappingAction MissingMappingAction.Passthrough
MissingSchemaAction MissingSchemaAction.Add

Vous pouvez modifier la valeur de l’une de ces propriétés via un appel séparé à la propriété.You can change the value of any of these properties through a separate call to the property.

Voir aussi

OdbcDataAdapter(String, OdbcConnection) OdbcDataAdapter(String, OdbcConnection) OdbcDataAdapter(String, OdbcConnection) OdbcDataAdapter(String, OdbcConnection)

Initialise une nouvelle instance de la classe OdbcDataAdapter avec une instruction SQL SELECT et OdbcConnection.Initializes a new instance of the OdbcDataAdapter class with an SQL SELECT statement and an OdbcConnection.

public:
 OdbcDataAdapter(System::String ^ selectCommandText, System::Data::Odbc::OdbcConnection ^ selectConnection);
public OdbcDataAdapter (string selectCommandText, System.Data.Odbc.OdbcConnection selectConnection);
new System.Data.Odbc.OdbcDataAdapter : string * System.Data.Odbc.OdbcConnection -> System.Data.Odbc.OdbcDataAdapter
Public Sub New (selectCommandText As String, selectConnection As OdbcConnection)

Paramètres

selectCommandText
String String String String

Une chaîne qui est une instruction SQL SELECT ou une procédure stockée devant être utilisée par la propriété SelectCommand de OdbcDataAdapter.A string that is a SQL SELECT statement or stored procedure to be used by the SelectCommand property of the OdbcDataAdapter.

selectConnection
OdbcConnection OdbcConnection OdbcConnection OdbcConnection

OdbcConnection qui représente la connexion.An OdbcConnection that represents the connection.

Exemples

L’exemple suivant crée un OdbcDataAdapter et définit certaines de ses propriétés.The following example creates an OdbcDataAdapter and sets some of its properties.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add( _
        "@oldCustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Remarques

Cette implémentation de OdbcDataAdapter peut être utile dans une application qui doit appeler la Fill méthode pour deux objets ou plus OdbcDataAdapter .This implementation of the OdbcDataAdapter can be useful in an application that must call the Fill method for two or more OdbcDataAdapter objects.

Voir aussi

OdbcDataAdapter(String, String) OdbcDataAdapter(String, String) OdbcDataAdapter(String, String) OdbcDataAdapter(String, String)

Initialise une nouvelle instance de la classe OdbcDataAdapter avec une instruction SQL SELECT et une chaîne de connexion.Initializes a new instance of the OdbcDataAdapter class with an SQL SELECT statement and a connection string.

public:
 OdbcDataAdapter(System::String ^ selectCommandText, System::String ^ selectConnectionString);
public OdbcDataAdapter (string selectCommandText, string selectConnectionString);
new System.Data.Odbc.OdbcDataAdapter : string * string -> System.Data.Odbc.OdbcDataAdapter
Public Sub New (selectCommandText As String, selectConnectionString As String)

Paramètres

selectCommandText
String String String String

Une chaîne qui est une instruction SQL SELECT ou une procédure stockée devant être utilisée par la propriété SelectCommand de OdbcDataAdapter.A string that is a SQL SELECT statement or stored procedure to be used by the SelectCommand property of the OdbcDataAdapter.

selectConnectionString
String String String String

Chaîne de connexionThe connection string.

Exemples

L’exemple suivant crée un OdbcDataAdapter et définit certaines de ses propriétés.The following example creates an OdbcDataAdapter and sets some of its properties.

public static OdbcDataAdapter CreateDataAdapter(
    OdbcConnection connection)
{
    string selectCommand =
        "SELECT CustomerID, CompanyName FROM Customers";

    OdbcDataAdapter adapter = new OdbcDataAdapter(
        selectCommand, connection);
    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OdbcCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OdbcCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OdbcCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName",
        OdbcType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID",
        OdbcType.Char, 5, "CustomerID").SourceVersion =
        DataRowVersion.Original;

    return adapter;
}
Public Function CreateDataAdapter( _
    ByVal connection As OdbcConnection) As OdbcDataAdapter

    Dim selectCommand As String = _
        "SELECT CustomerID, CompanyName FROM Customers"
    Dim adapter As OdbcDataAdapter = _
        New OdbcDataAdapter(selectCommand, connection)

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    ' Create the Insert, Update and Delete commands.
    adapter.InsertCommand = New OdbcCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
         "VALUES (?, ?)")

    adapter.UpdateCommand = New OdbcCommand( _
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " & _
        "WHERE CustomerID = ?")

    adapter.DeleteCommand = New OdbcCommand( _
        "DELETE FROM Customers WHERE CustomerID = ?")

    ' Create the parameters.
    adapter.InsertCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.InsertCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")

    adapter.UpdateCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID")
    adapter.UpdateCommand.Parameters.Add( _
        "@CompanyName", OdbcType.VarChar, 40, "CompanyName")
    adapter.UpdateCommand.Parameters.Add( _
        "@oldCustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    adapter.DeleteCommand.Parameters.Add( _
        "@CustomerID", OdbcType.Char, 5, "CustomerID").SourceVersion = _
        DataRowVersion.Original

    Return adapter
End Function

Remarques

Cette surcharge du OdbcDataAdapter constructeur utilise le selectConnectionString paramètre pour définir la SelectCommand propriété.This overload of the OdbcDataAdapter constructor uses the selectConnectionString parameter to set the SelectCommand property. Toutefois, il n’ouvre pas la connexion.However, it does not open the connection. Vous devez toujours ouvrir explicitement la connexion.You still must explicitly open the connection.

Voir aussi

S’applique à