Send feedback on this topic.
Teradata.Client.Provider
TdCommandBuilder Class
Members  Example 



Teradata.Client.Provider Namespace : TdCommandBuilder Class
The TdCommandBuilder generates DML statements (UPDATE, INSERT and DELETE) which are used by TdDataAdapter. The TdDataAdapter applies changes to a DataSet (or DataTable) back to the Teradata Vantage Advanced SQL Engine.
Object Model
TdCommandBuilder ClassTdDataAdapter ClassTdCommand ClassTdCommand ClassTdCommand Class
Syntax
'Declaration
 
Public NotInheritable Class TdCommandBuilder 
   Inherits System.Data.Common.DbCommandBuilder
   Implements System.ComponentModel.IComponentSystem.IDisposable 
'Usage
 
Dim instance As TdCommandBuilder
public ref class TdCommandBuilder sealed : public System.Data.Common.DbCommandBuilder, System.ComponentModel.IComponentSystem.IDisposable  
Remarks

TdCommandBuilder can generate DML (UPDATE, DELETE and INSERT) statements for a single table SELECT statement. TdCommandBuilder uses the SelectCommand property of the associated TdDataAdapter to retrieve column information. Later, column information is used to generate UPDATE, DELETE or INSERT statements. The target-row for an UPDATE or a DELETE statement is identified by The WHERE clause.

If it is included in the SELECT statement, the TdCommandBuilder will use the primary key column(s) to uniquely identify the target-row for an UPDATE or a DELETE statement. Otherwise, all columns returned by the SELECT statement are added to the WHERE clause

TdCommandBuilder will register as a listener for RowUpdating events generated by the associated TdDataAdapter (TdCommandBuilder.DataAdapter property). TdCommandBuilder will generate a new DML statement and set the TdRowUpdatingEventArgs. Command property. DML statements are generated based on the columns that are changed (UPDATE) in an updated row or columns that are inserted (INSERT) into a brand new row (TdRowUpdatingEventArgs.Row). Therefore, UPDATE and INSERT statements are generated for each RowUpdating event while the DELETE statement is static until the next call to TdCommandBuilder.RefreshSchema method.

You should call TdCommandBuilder.RefreshSchema if the SelectCommand property of the associated TdDataAdapter (TdCommandBuilder.DataAdapter property) has changed. RefreshSchema method updates the column information used to generate UPDATE, DELETE and INSERT statements in addition to updating the TdConnection and TdTransaction used for the Update.

Example
public void DisplayUpdateCustomersTable(String connectionString, String commandText)
{
   TdConnection cn = new TdConnection(connectionString);
     
   try
   {
       // Open a connection to Teradata
       cn.Open();
    
       // Create a new adapter.
       TdDataAdapter adapter = new TdAdapter(commandText, cn);
            
       // Create a new command builder to generate DML statements.
       TdCommandBuilder cmdBuilder = new TdCommandBuilder(adapter);
              
       // Cache the results in a dataset
       DataSet ds = new DataSet();
       adapter.fill(ds, “Call_Log”);
            
       // Display the table to user using DataGrid or other interfaces
       // Finally apply the changes back to the Teradata
       // Note that TdDataAdapter.UpdateCommand, InsertCommand and 
       // DeleteCommand is generated by TdCommandBuilder.
       adapter.Update(ds, “Call_Log”);
   }
   finally
   {
       cn.Close();
   }
}
Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DbCommandBuilder
            Teradata.Client.Provider.TdCommandBuilder

Requirements

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

See Also

Reference

TdCommandBuilder Members
Teradata.Client.Provider Namespace