Export (0) Print
Expand All

OdbcCommand.Cancel Method

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

Attempts to cancel the execution of an OdbcCommand.

[Visual Basic]
Public Overridable Sub Cancel() Implements IDbCommand.Cancel
[C#]
public virtual void Cancel();
[C++]
public: virtual void Cancel();
[JScript]
public function Cancel();

Implements

IDbCommand.Cancel

Remarks

If there is nothing to cancel, nothing happens. However, if there is a command in process, and the attempt to cancel fails, no exception is generated.

Example

[Visual Basic, C#, C++] The following example creates an OdbcCommand, executes it, then cancels the execution. To accomplish this, the method is passed a string that is an SQL SELECT statement and a string to use to connect to the data source.

[Visual Basic] 
Public Sub CreateMyOdbcCommand _
(mySelectQuery As String, myConnectionString As String)
    Dim myConnection As New OdbcConnection(myConnectionString)
    Dim myCommand As New OdbcCommand(mySelectQuery, myConnection)
    myCommand.Connection.Open()
    myCommand.ExecuteReader()
    myCommand.Cancel()
End Sub

[C#] 
public void CreateMyOdbcCommand(string mySelectQuery, string myConnectionString) 
{
   OdbcConnection myConnection = new OdbcConnection(myConnectionString);
   OdbcCommand myCommand = new OdbcCommand(mySelectQuery, myConnection);
   myCommand.Connection.Open();
   myCommand.ExecuteReader();
   myCommand.Cancel();
}

[C++] 
public:
    void CreateMyOdbcCommand(String* mySelectQuery, String* myConnectionString)
    {
        OdbcConnection* myConnection = new OdbcConnection(myConnectionString);
        OdbcCommand* myCommand = new OdbcCommand(mySelectQuery, myConnection);
        myCommand->Connection->Open();
        myCommand->ExecuteReader();
        myCommand->Cancel();
    };

[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

Show:
© 2015 Microsoft