Insert data into DataRow(System.Data.DataRow) variable

I have created a variable ‘SalesData’ of type System.Data.DataRow. I have a data table(SalesTable). And I want to insert the first-row of SalesTable into SalesData.
When I try to add data into that SalesData variable using assign activity iterating through columns of the SalesTable using ForEach activity, getting below error.
“Assign: Cannot create an L-value from the given expression with property ‘set_Item’ because the target object is null.”
How can I achieve it?

2 Likes

Hi @krishnakanth.k

have you use Row.Item(“column name”)=salesData in assign activity

If you find it useful mark it as solution and close the thread.

Cool,
Regards,
Gulshiyaa

@krishnakanth.k

IT seems to me, that filling Up the datarow with values fails, because you have declared the variable but the variable ist not initialized. From there the null issue should come from.

Assumed the Datatable is correct initialized e.g with a build Data table Activity you can do following for a First round Just to explore functionalities.

Create an Array of objects with the values for the different columns belonging to a datarow and add this Array with add datarow Activity to the Datatable.

Explore on how a datarow can be initialized with
Assign Activity and assign yourdatatablevar.newRow to your datarowvariable

If this ist done the Syntax given by @gulshiyaa should Work aß Well to Set values to the different columns

I’m using the same syntax. But, facing issue

yeah, this might be the issue.
But, no luck. I didn’t find anything related to initializing DataRow variable.

Hi @krishnakanth.k,

Step:1
Create 2 Variable’s → 1.SalesTable as DataTable & 2.Data_Row as DataRow
Step:2
Assign Activity → Data_Row = SalesTable.NewRow
Step:3
Assign Activity → Data_Row(“ColumnName”) = “Value”
Step:4
Add DataRow Activity → input parameter should be -->Datarow = Data_Row & DataTable = SalesTable.

Try these steps & let me know…

8 Likes

below that have you use write range activity?

@krishnakanth.k

@Vivek.A.S gave a perfect description on the steps. Between Step 1 & 2 I recommend to do following:

Use a build Datatabpe Activity, or add the needed rows with add data column activity.
After done with this Step 2 return you a datarow within the structure that you have defined in the steps from above

Let us know on how its working

1 Like

@Vivek.A.S
Thanks, Vivek. This solution is working.

Thank you @krishnakanth.k

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.