Export (0) Print
Expand All

OdbcCommand.CommandType Property

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

Gets or sets a value indicating how the CommandText property is interpreted.

[Visual Basic]
Public Overridable Property CommandType As CommandType  Implements _
   IDbCommand.CommandType
[C#]
public virtual CommandType CommandType {get; set;}
[C++]
public: __property virtual CommandType get_CommandType();
public: __property virtual void set_CommandType(CommandType);
[JScript]
public function get CommandType() : CommandType;
public function set CommandType(CommandType);

Property Value

One of the CommandType values. The default is Text.

Implements

IDbCommand.CommandType

Exceptions

Exception Type Condition
ArgumentException The value was not a valid CommandType.

Remarks

When the CommandType property is set to StoredProcedure, you should set the CommandText property to the full ODBC call syntax. The command then executes this stored procedure when you call one of the Execute methods (for example, ExecuteReader or ExecuteNonQuery).

The Connection, CommandType and CommandText properties cannot be set if the current connection is performing an execute or fetch operation.

The .NET Framework Data Provider for ODBC does not support passing named parameters to an SQL statement or to a stored procedure called by an OdbcCommand. In either of these cases, use the question mark (?) placeholder. For example:

SELECT * FROM Customers WHERE CustomerID = ?

The order in which OdbcParameter objects are added to the OdbcParameterCollection must directly correspond to the position of the question mark placeholder for the parameter.

For more information, see Using Stored Procedures with a Command.

Note   The .NET Framework Data Provider for ODBC does not support the CommandType setting of TableDirect.

Example

[Visual Basic, C#, C++] The following example creates an instance of a derived class OdbcCommand and sets some of its properties.

[Visual Basic] 
Public Sub CreateMyOdbcCommand()
    Dim myCommand As New OdbcCommand()
    myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"
    myCommand.CommandType = CommandType.Text
End Sub

[C#] 
public void CreateMyOdbcCommand() 
{
   OdbcCommand myCommand = new OdbcCommand();
   myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
   myCommand.CommandType = CommandType.Text;
}

[C++] 
public:
    void CreateMyOdbcCommand()
    {
        OdbcCommand* myCommand = new OdbcCommand();
        myCommand->CommandText = S"SELECT * FROM Categories ORDER BY CategoryID";
        myCommand->CommandType = CommandType::Text;
    };

[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

OdbcCommand Class | OdbcCommand Members | System.Data.Odbc Namespace | CommandText | UpdatedRowSource

Show:
© 2014 Microsoft