This documentation is archived and is not being maintained.

OdbcDataAdapter.SelectCommand Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

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

[Visual Basic]
Public Shadows Property SelectCommand As OdbcCommand
[C#]
public new OdbcCommand SelectCommand {get; set;}
[C++]
public: __property OdbcCommand* get_SelectCommand();
public: __property void set_SelectCommand(OdbcCommand*);
[JScript]
public hide function get SelectCommand() : OdbcCommand;
public function set SelectCommand(OdbcCommand);

Property Value

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

Remarks

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 does not return any rows, no tables are added to the DataSet, and no exception is raised.

Example

[Visual Basic, C#, C++] The following example creates an OdbcDataAdapter and sets the SelectCommand and InsertCommand properties. It assumes you have already created an OdbcConnection object.

[Visual Basic] 
Public Shared Function CreateCustomerAdapter(conn As OdbcConnection) As OdbcDataAdapter 
  
  Dim da As OdbcDataAdapter = New OdbcDataAdapter()
  Dim cmd As OdbcCommand
  Dim parm As OdbcParameter

  ' Create the SelectCommand.

  cmd = New OdbcCommand("SELECT * FROM Customers " & _
                       "WHERE Country = ? AND City = ?", conn)

  cmd.Parameters.Add("@Country", OdbcType.NVarChar, 15)
  cmd.Parameters.Add("@City", OdbcType.NVarChar, 15)

  da.SelectCommand = cmd

  ' Create the DeleteCommand.

  cmd = New OdbcCommand("DELETE FROM Customers WHERE CustomerID = ?", conn)

  parm = cmd.Parameters.Add("@CustomerID", OdbcType.NChar, 5, "CustomerID")
  parm.SourceVersion = DataRowVersion.Original

  da.DeleteCommand = cmd

  Return da
End Function

[C#] 
public static OdbcDataAdapter CreateCustomerAdapter(OdbcConnection conn)
{
  OdbcDataAdapter da = new OdbcDataAdapter();
  OdbcCommand cmd;
  OdbcParameter parm;

  // Create the SelectCommand.

  cmd = new OdbcCommand("SELECT * FROM Customers " +
                       "WHERE Country = ? AND City = ?", conn);

  cmd.Parameters.Add("@Country", OdbcType.NVarChar, 15);
  cmd.Parameters.Add("@City", OdbcType.NVarChar, 15);

  da.SelectCommand = cmd;

  // Create the DeleteCommand.

  cmd = new OdbcCommand("DELETE FROM Customers WHERE CustomerID = ?", conn);

  parm = cmd.Parameters.Add("@CustomerID", OdbcType.NChar, 5, "CustomerID");
  parm.SourceVersion = DataRowVersion.Original;

  da.DeleteCommand = cmd;

  return da;
}

[C++] 
public:
    static OdbcDataAdapter* CreateCustomerAdapter(OdbcConnection* conn)
    {
        OdbcDataAdapter* da = new OdbcDataAdapter();
        OdbcCommand* cmd;
        OdbcParameter* parm;

        // Create the SelectCommand.
        cmd = new OdbcCommand(S"SELECT * FROM Customers WHERE Country = ? AND City = ?", conn);

        cmd->Parameters->Add(S"@Country", OdbcType::NVarChar, 15);
        cmd->Parameters->Add(S"@City", OdbcType::NVarChar, 15);

        da->SelectCommand = cmd;

        // Create the DeleteCommand.
        cmd = new OdbcCommand(S"DELETE FROM Customers WHERE CustomerID = ?", conn);

        parm = cmd->Parameters->Add(S"@CustomerID", OdbcType::NChar, 5, S"CustomerID");
        parm->SourceVersion = DataRowVersion::Original;

        da->DeleteCommand = cmd;

        return da;
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OdbcDataAdapter Class | OdbcDataAdapter Members | System.Data.Odbc Namespace | DeleteCommand | InsertCommand | UpdateCommand

Show: