How to change the position of row

Hi Team,

I need to change the row as bottom to top without giving any condition in csv file…

Example

Col1 col2 col3
1 aaa ww
2 bbb yy
3 ccc mm

Output:

Col1 col2 col3
3 ccc mm
2 bbb yy
1 aaa ww

Kindly provide any solution for this…

Thanks

1 Like

Hi @vaishali ,
You can try this Step

  1. Get the Row having Total in it’s First Column
  2. Convert the Row to Object Array and Store it.
  3. Delete the Total Row from the Datatable.
  4. Use Add Data Row Activity with Object Array as the input value which in turn contains the total row value.
    regards,
    LNV
1 Like

Hi @vaishali

=> Use read csv activity to read the csv file and store it in a datatable. Output - dt_csv
=> After this take an assign activity and create another datatable variable, let’s call it as dt_Reversed.

- Assign -> dt_Reversed = dt_csv.AsEnumerable().Reverse().CopyToDataTable()

=> At last, use write csv activity to write the dt_Reversed datatable to csv file.

Hope it helps!!

Hi @vaishali

You can simply try this

ReversedDataTable=(From row In DataTable.AsEnumerable() Select row).Reverse().CopyToDataTable()

1 Like

Thanks for the input… Its working as expected. But once we write the output its creates the empty three rows. May I know why we are getting that again .do we need to delte the empty row… Please suggest.

1 Like

Thanks for the reply. As i said we are getting some empty row… Do we need to write the code to remove the empty row.

@vaishali

Is the empty row adding first or in between can you show some screenshot how it looks

Assign Activity
dr1 | DataType: DataRow = YourDataTable.Rows(0)
Assign Activity
dr2 | DataType: DataRow = YourDataTable.AsEnumerable().Last().ItemArray
Assign Activity
raTMP | Object() - Object Array | dr1.ItemArray
Assign Activity:
dr1.ItemArray = dr2.ItemArray
Assign Activity:
dr2.IttemArray = raTMP

EDITED - Shortened
Assign Activity
raTMP | Object() - Object Array | YourDataTable.Rows(0).ItemArray

Assign Activity
YourDataTable.Rows(0).ItemArray = YourDataTable.AsEnumerable().Last().ItemArray

Assign Activity:
YourDataTable.AsEnumerable().Last().ItemArray = raTMP

1 Like

Yes its working as excepted thanks

1 Like

Perfect, so it is ensured that your data table row count will always be 3

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