Condividi tramite


OdbcDataAdapter Costruttori

Definizione

Inizializza una nuova istanza della classe OdbcDataAdapter.

Overload

OdbcDataAdapter()

Inizializza una nuova istanza della classe OdbcDataAdapter.

OdbcDataAdapter(OdbcCommand)

Inizializza una nuova istanza della classe OdbcDataAdapter con l'istruzione SQL SELECT specificata.

OdbcDataAdapter(String, OdbcConnection)

Inizializza una nuova istanza della classe OdbcDataAdapter con un'istruzione SQL SELECT e una classe OdbcConnection.

OdbcDataAdapter(String, String)

Inizializza una nuova istanza della classe OdbcDataAdapter con un'istruzione SQL SELECT e una stringa di connessione.

OdbcDataAdapter()

Origine:
OdbcDataAdapter.cs
Origine:
OdbcDataAdapter.cs

Inizializza una nuova istanza della classe OdbcDataAdapter.

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

Esempio

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

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

Commenti

Quando si crea un'istanza di OdbcDataAdapter, le proprietà di sola scrittura e di sola lettura seguenti vengono impostate sui valori predefiniti, come illustrato nella tabella.

Proprietà Valore predefinito
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

OdbcDataAdapter(OdbcCommand)

Origine:
OdbcDataAdapter.cs
Origine:
OdbcDataAdapter.cs

Inizializza una nuova istanza della classe OdbcDataAdapter con l'istruzione SQL SELECT specificata.

public:
 OdbcDataAdapter(System::Data::Odbc::OdbcCommand ^ selectCommand);
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)

Parametri

selectCommand
OdbcCommand

Classe OdbcCommand che è un'istruzione SQL SELECT o una stored procedure e viene impostata come la proprietà SelectCommand della classe OdbcDataAdapter.

Esempio

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

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

Commenti

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

Quando si crea un'istanza di OdbcDataAdapter, le proprietà di sola scrittura e di sola lettura seguenti vengono impostate sui valori predefiniti, come illustrato nella tabella.

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

OdbcDataAdapter(String, OdbcConnection)

Origine:
OdbcDataAdapter.cs
Origine:
OdbcDataAdapter.cs

Inizializza una nuova istanza della classe OdbcDataAdapter con un'istruzione SQL SELECT e una classe OdbcConnection.

public:
 OdbcDataAdapter(System::String ^ selectCommandText, System::Data::Odbc::OdbcConnection ^ selectConnection);
public OdbcDataAdapter (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)

Parametri

selectCommandText
String

Una stringa che è un'istruzione SQL SELECT o una stored procedure che viene utilizzata dalla proprietà SelectCommand dell'oggetto OdbcDataAdapter.

selectConnection
OdbcConnection

Classe OdbcConnection che rappresenta la connessione.

Esempio

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

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

Commenti

Questa implementazione di OdbcDataAdapter può essere utile in un'applicazione che deve chiamare il Fill metodo per due o più OdbcDataAdapter oggetti.

Vedi anche

Si applica a

OdbcDataAdapter(String, String)

Origine:
OdbcDataAdapter.cs
Origine:
OdbcDataAdapter.cs

Inizializza una nuova istanza della classe OdbcDataAdapter con un'istruzione SQL SELECT e una stringa di connessione.

public:
 OdbcDataAdapter(System::String ^ selectCommandText, System::String ^ selectConnectionString);
public OdbcDataAdapter (string? selectCommandText, 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)

Parametri

selectCommandText
String

Una stringa che è un'istruzione SQL SELECT o una stored procedure che viene utilizzata dalla proprietà SelectCommand dell'oggetto OdbcDataAdapter.

selectConnectionString
String

Stringa di connessione.

Esempio

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

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

Commenti

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

Vedi anche

Si applica a