OdbcDataAdapter Constructor (String, OdbcConnection)

 

Initializes a new instance of the OdbcDataAdapter class with an SQL SELECT statement and an OdbcConnection.

Namespace:   System.Data.Odbc
Assembly:  System.Data (in System.Data.dll)

public OdbcDataAdapter(
	string selectCommandText,
	OdbcConnection selectConnection
)

Parameters

selectCommandText
Type: System.String

A string that is a SQL SELECT statement or stored procedure to be used by the SelectCommand property of the OdbcDataAdapter.

selectConnection
Type: System.Data.Odbc.OdbcConnection

An OdbcConnection that represents the connection.

This implementation of the OdbcDataAdapter can be useful in an application that must call the Fill method for two or more OdbcDataAdapter objects.

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;
}

.NET Framework
Available since 1.1
Return to top
Show: