Which TWO methods are valid ways to add a new column to an existing DataTable?
This is the standard and most efficient way to programmatically add a new column to a DataTable. It allows you to specify both the name and the data type of the column, ensuring the DataTable structure is updated correctly in memory for subsequent row-based data processing tasks.
Why this answer
Adding columns to a DataTable at runtime is a common requirement when enriching data during processing. Both the 'Add' method of the Columns collection and the use of 'Invoke Code' are valid ways to achieve this. Knowing these methods allows developers to dynamically expand data structures without needing to define complex schemas in the project design phase, increasing automation flexibility.
Exam trap
Candidates often assume that simply defining a variable is enough, forgetting that a DataTable requires a defined schema with column types before data rows can be added.