QuestionQ28

Data Manipulation

A developer used the Add Data Row activity to insert a row into a data table named "dt_Reports". However, at runtime, UiPath Studio throws an exception:

"Add Data Row: Object reference not set to an instance of an object," because the data table has not been initialized.

What should the developer add in an Assign activity before the Add Data Row activity to fix this issue?

Explanation

The exception occurs because the dt_Reports DataTable variable is null at runtime — it was declared but never instantiated. To resolve this, an Assign activity must be placed before the Add Data Row activity to initialize the variable by creating a new instance of the DataTable object: dt_Reports = New System.Data.DataTable. This follows standard .NET object initialization syntax, where the variable name appears on the left side of the assignment and the object instantiation (using the New keyword with the correct type, System.Data.DataTable) appears on the right side. Once initialized, the DataTable object reference is valid, allowing the Add Data Row activity to successfully add a row without throwing a null reference exception.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!