OdbcDataAdapter.SelectCommand Property


Gets or sets an SQL statement or stored procedure used to select records in the data source.

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

public OdbcCommand SelectCommand { get; set; }

Property Value

Type: System.Data.Odbc.OdbcCommand

An OdbcCommand that is used during a fill operation to select records from data source for placement in the DataSet.

When SelectCommand is assigned to a previously created OdbcCommand, the OdbcCommand is not cloned. Instead, the SelectCommand maintains a reference to the previously created OdbcCommand object.

If SelectCommand returns no rows, no tables are added to the DataSet, and no exception is raised.

The following example creates an OdbcDataAdapter and sets the SelectCommand and InsertCommand properties. It assumes that you have already created an OdbcConnection object.

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.
        OdbcType.Char, 5, "CustomerID");
        OdbcType.VarChar, 40, "CompanyName");

        OdbcType.Char, 5, "CustomerID");
        OdbcType.VarChar, 40, "CompanyName");
        OdbcType.Char, 5, "CustomerID").SourceVersion =

        OdbcType.Char, 5, "CustomerID").SourceVersion =

    return adapter;

.NET Framework
Available since 1.1
Return to top