This documentation is archived and is not being maintained.

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 */
public OdbcCommand get_SelectCommand ()

/** @property */
public void set_SelectCommand (OdbcCommand value)

public function get SelectCommand () : OdbcCommand

public function set SelectCommand (value : OdbcCommand)

Property Value

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


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1
Show: