Send feedback on this topic.
Teradata.Client.Provider
Visual Studio Support
.NET Data Provider for Teradata > Developer's Guide > Working with the Data Provider Features > Generated Data Retrieval (Identity Column Support) > Visual Studio Support

Microsoft Visual Studio supports Generated Data Retrieval through configuration of the TdDataAdapter in Windows Form Projects. TableAdapters provide communication between your application and a database. A TableAdapter connects to the database and is responsible for executing queries against the database to populate DataTables and to provide synchronization between the DataTable and the database table.

Windows Form Designer

Microsoft Visual StudioWindows projects may configure the TdDataAdapter by dragging and dropping the TdDataAdapter from the Visual Studio ToolBox onto a Windows Form.  The ToolBox must be initialized with the .NET Data Provider for Teradata 15.0.0.0 components before dragging and dropping the TdDataAdapter from the Toolbox onto the Windows Form. An icon will appear below the Windows Form. Selecting the TdDataAdapter from the bottom of the Windows Form Designer will display a designer arrow above the TdDataAdapter. Selecting this arrow and selecting the Configure Data Adapter will enable configuration of the DataAdapter. Please follow the configuration wizard instructions to generate the appropriate commands. Delete and Update commands will only be generated against database tables/views that contain primary keys. After configuration is complete, select the properties of the TdDataAdapter displaying the properties in the property window. Select the insert command property GeneratedDataBehavior and use the drop down list box to select either IdentityColumn or AllColumns. This will enable the defined DataTable to update column values from insert or insert-select statement types executed against the database table.

Windows Typed Dataset Designer

The TdDataAdapter may also be configured utilizing the data adapter configuration wizard in the Typed Dataset Designer. A Data Source may be defined by selecting tables or views from Teradata in the Data Sources view.  Selecting the Data Source Add a New Data Source button will enable the Data Source configuration wizard. Follow the instructions defining a Teradata Data Source. This will create a Dataset that contains a TableAdapter with generated commands to support your selected database object. Remember that the update and delete commands will only be generated for database tables/views that contain a primary key.

Configuration of the Data Source will create a Dataset that contains a TableAdapter. To support Generated Data Retrieval, a code modification must be performed to the Dataset designer code. The designer generates code to initialize the TableAdapter.  This method InitAdapter () is generated which contains code to initialize the selected commands from the Data Source configuration wizard. The insert command (if selected) needs to define the GeneratedDataBehavior property to enable the DataTable rows to reflect generated data from the database insert or insert-select statement types. This code is a sample generated portion to illustrate the property addition.

C#
Copy Code
private void InitAdapter()
{
   this._adapter = new Teradata.Client.Provider.TdDataAdapter ();
   System.Data.Common.DataTableMapping tableMapping = new System.Data.Common.DataTableMapping ();
   tableMapping.SourceTable = "Table";
   tableMapping.DataSetTable = "IdBak";
   tableMapping.ColumnMappings.Add("c1", "c1");
   tableMapping.ColumnMappings.Add("c2", "c2");
   tableMapping.ColumnMappings.Add("c3", "c3");
   tableMapping.ColumnMappings.Add("c4", "c4");
   tableMapping.ColumnMappings.Add("idcol", "idcol");
   this._adapter.TableMappings.Add(tableMapping);
   this._adapter.InsertCommand = new Teradata.Client.Provider.TdCommand ();
   this._adapter.InsertCommand.Connection = this.Connection;
   this._adapter.InsertCommand.CommandText =
       "INSERT INTO \"cc2\".\"IdBak\" (\"c1\", \"c2\", \"c3\", \"c4\", \"idcol\") VALUES (?, ?, ?, ?, ?)";
   this._adapter.InsertCommand.CommandType = System.Data.CommandType.Text;


}

Enabling generated data behavior in this DataAdapter requires an additional line of code setting the insert command GeneratedDataBehavior property to either AllColumns or IdentityColumn.

C#
Copy Code
    this._adapter.InsertCommand.GeneratedDataBehavior =
        Teradata.Client.Provider.GeneratedDataBehavior.AllColumns;