See Also

DbCommandBase Class  | DbCommandBase Members

Language

Visual Basic

C#

Show All

result
The IAsyncResult returned from BeginExecuteNonQuery.
See AlsoLanguagesDevart.DataSend comments on this topic.

EndExecuteNonQuery Method

Devart.Common Namespace > DbCommandBase Class : EndExecuteNonQuery Method

Ends an asynchronous invocation of the ExecuteNonQuery method.

[Visual Basic]
Public Function EndExecuteNonQuery( _    ByVal result As IAsyncResult _ ) As Integer
[C#]
public int EndExecuteNonQuery(    IAsyncResult result );

Parameters

result
The IAsyncResult returned from BeginExecuteNonQuery.

Return Type

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.

Remarks

The function ends an asynchronous execution of a query that is started with BeginExecuteNonQuery. A pair of asynchronous functions (BeginExecuteNonQuery and EndExecuteNonQuery) can be used instead of the synchronous function ExecuteNonQuery to gain more performance and flexibility in your application.

Refer to "Asynchronous Query Execution" article for detailed information.

Example

In the example below an easiest way of executing an asynchronous operation is shown. First, all components are set up and a connection is opened. Second, a query execution is started. The operation state (done or in progress) is checked and a report is written to the console. At last query result is rendered.

[C#] 

static void Async_Exec(DbConnectionBase myConnection) 

  DbCommandBase myCommand = (DbCommandBase)myConnection.CreateCommand(); 
  myCommand.CommandText = "UPDATE Test.Dept SET DName='New Department' WHERE DeptNo=10"; 
  Console.WriteLine("Starting asynchronous query execution..."); 
  myConnection.Open(); 
  IAsyncResult cres = myCommand.BeginExecuteNonQuery(null, null); 
  if (cres.IsCompleted) 
    Console.WriteLine("Completed."); 
  else 
    Console.WriteLine("Have to wait for operation to complete..."); 
  try 
  { 
    int RowsAffected = myCommand.EndExecuteNonQuery(cres); 
    Console.WriteLine("Done. Rows affected: " + RowsAffected.ToString()); 
  } 
  catch (Exception e) 
  { 
    Console.WriteLine("An exception has occurred: " + e.Message); 
  } 
  finally 
  { 
    myConnection.Close(); 
  } 

[Visual Basic] 

Public Sub Async_Exec(ByVal myConnection As DbConnectionBase)
  Dim myCommand As DbCommandBase = myConnection.CreateCommand()
  myCommand.CommandText = "UPDATE Test.Dept SET DName='New Department' WHERE DeptNo=20"
  Console.WriteLine("Starting asynchronous query execution...")
  myConnection.Open()
  Dim cres As IAsyncResult = myCommand.BeginExecuteNonQuery(Nothing, Nothing)
  If cres.IsCompleted Then
    Console.WriteLine("Completed.")
  Else
    Console.WriteLine("Have to wait for operation to complete...")
  End If
  Try
    Dim RowsAffected As Integer = myCommand.EndExecuteNonQuery(cres)
    Console.WriteLine(String.Concat("Rows affected: ", RowsAffected.ToString()))
  Catch e As Exception
    Console.WriteLine(String.Concat("An exception has occurred: ", e.Message))
  Finally
    myConnection.Close()
  End Try
End Sub

See Also

DbCommandBase Class  | DbCommandBase Members

 

 


© 2002 - 2013 Devart. All Rights Reserved.