This documentation is archived and is not being maintained.

OleDbCommand.Cancel Method

Attempts to cancel the execution of an OleDbCommand.

[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 OleDbCommand, executes it, then cancels the execution. To accomplish this, the method is passed a string that is a SQL Select statement and a string to use to connect to the data source.

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

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

[C++] 
public:
 void CreateMyOleDbCommand(String* mySelectQuery, String* myConnectionString) 
 {
    OleDbConnection* myConnection = new OleDbConnection(myConnectionString);
    OleDbCommand* myCommand = new OleDbCommand(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

OleDbCommand Class | OleDbCommand Members | System.Data.OleDb Namespace

Show: