Send feedback on this topic.
Teradata.Client.Provider
BeginExecuteNonQuery(AsyncCallback,Object) Method
Example 



Teradata.Client.Provider Namespace > TdCommand Class > BeginExecuteNonQuery Method : BeginExecuteNonQuery(AsyncCallback,Object) Method
Delegate that will be invoked after the processing of the request has completed. If one is not required a null is specified.
User defined object. This object is available to the callback procedure by accessing the IAsyncResult.AsyncState property.
Initiates an asynchronous request to Teradata. This method differs from TdCommand.BeginExecuteReader in that it should not be used when retrieving data. A TdDataReader object is not returned when the corresponding TdCommand.EndExecuteNonQuery method is called.
Syntax
'Declaration
 
Public Overloads Function BeginExecuteNonQuery( _
   ByVal callback As AsyncCallback, _
   ByVal state As Object _
) As IAsyncResult
'Usage
 
Dim instance As TdCommand
Dim callback As AsyncCallback
Dim state As Object
Dim value As IAsyncResult
 
value = instance.BeginExecuteNonQuery(callback, state)
public IAsyncResult BeginExecuteNonQuery( 
   AsyncCallback callback,
   object state
)
public:
IAsyncResult^ BeginExecuteNonQuery( 
   AsyncCallback^ callback,
   Object^ state
) 

Parameters

callback
Delegate that will be invoked after the processing of the request has completed. If one is not required a null is specified.
state
User defined object. This object is available to the callback procedure by accessing the IAsyncResult.AsyncState property.

Return Value

Returns a IAsyncResult object.
Exceptions
ExceptionDescription
The TdParameter.Offset is outside of 0 through array size � 1.
One or more parameters cannot be converted to the Advanced SQL Engine native types.
Can be thrown because of one of the following errors: 1) TdConnection is not in Open state or is null or 2) The local transaction associated with the TdCommand is not the same local transaction associated with the TdConnection. Assign the local transaction to Transaction property.
The TdCommand is closed / disposed.
Can be thrown the Data Provider detected an error.
Remarks

The call to BeginExecuteNonQuery returns after the request has been successfully sent to Teradata. Any exceptions that are generated by the provider while initializing the request will be thrown during the call to BeginExecuteNonQuery. Exceptions that are generated by the provider or Teradata during the processing of the request will be thrown when EndExecuteNonQuery is called.

The DDL statement CREATE PROCEDURE cannot be specified in an asynchronous execution. If it has been specified a TdException will be thrown when TdCommand.EndExecuteNonQuery is called.

A connection can only have one active request. Therefore, if an asynchronous request is being processed by the provider an exception will be thrown when an attempt is made to start another asynchronous request.

The TdCommand.CommandTimeout property is not applicable to asynchronous execution and will be ignored when a command is asynchronously executed.

Refer to TdCommand.ExecuteNonQuery for more information.

Example
This example shows how BeginExecuteNonQuery can be used in a Winforms Application.
public partial class MainForm : Form
 {
     // Indicates the a query is being processed
     Boolean _processing = false;
            
     TdConnection _cn = null;
     String _connectionString = @"Data Source=Teradata1; " +
                "Initial Catalog=ProdDB; " +
                "Integrated Security=True;Pooling=False ";
            
     public MainForm()
     {
         InitializeComponent();
     }
            
     private void WarehouseCallback(IAsyncResult result)
     {
         TdCommand command = (TdCommand)result.AsyncState;
            
         try
         {
            command.EndExecuteNonQuery();
            
            MessageBox.Show("Database has been updated", "Information");
         }
         catch (TdException t)
         {
            MessageBox.Show(t.Errors[0].Message, "ERROR");
         }
         finally
         {
             _processing = false;
            
             _cn.Close();
         }
     }
 
     private void buttonSubmit_Click(object sender, EventArgs e)
     {
         //checking whether the form is already processing 
         //another query
         if (true = _processing)
         {
             MessageBox.Show(
                 "Currently updating warehouse information");
         }
         else
         {
             String warehouseSQL = "Update ProductWarehouse " +
                           "set ProdCount = " + textBoxProdCount.Text +
                           where ProdNo= " + textBoxProdNo.Text;
            
             try
             {
                 _processing = true;
            
                 //The application has already created the
                 //connection object.  The name of the object
                 //is _cn.
            
                 TdCommand command = _cn.CreateCommand();
                 command.CommandText = warehouseSQL;
            
                 //setting up the delegate for the asynchronous call
                 AsyncCallback callback = 
                          new AsyncCallback(WarehouseCallback);
            
                 //asynchronous call.  The WarehouseCallback callback
                 //will be invoked by the provider after processing of 
                 //the query has been completed.
                 command.BeginExecuteNonQuery(callback, command);
             }
             catch (TdException t)
             {
                 MessageBox.Show(t.Errors[0].Message);
            
                 _cn.Close();
             }
         }
     }
 }
Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdCommand Class
TdCommand Members
Overload List
ExecuteNonQuery Method