DataRow Into Datatable Using For Each Row Loop

Hello everyone,
I got problem with my DataTable, where there are multiple rows and columns. I need to extract data from spesific index of row and coulum. Kind like this, for the row I need to start from Index 1, and column start from Index-7. I’ve tried:

  1. Using “foreach loops row” from DataTable
    ForEach rowPosition in dataTable
    ForEach row in RowPosition
    Not working because the output of rowPosition is DataRow.

  2. Using Assign to get the index both for row and column, then put it into datatable
    rowIndex = dataTable.Rows.IndexOf(rowPosition)+1
    columnIndex = dataTable.Columns.IndexOf(“columnName”)+1
    dt2 = dtPayment.Rows(rowIndex)(columnIndex)
    Not working because of disallows converstion From Object To DataTable

  3. Using Add Data Row from Activities, where
    ForEach rowPosition in dataTable
    AddDataRow
    Input = rowPosition
    Output = newDT
    Not working because of “Add Data Row: Object reference not set to an instance of an object.”

I need to do subtraction between column-7 and column-8, column-9 and column-10, etc.

@kristoff So you want to Perform Subtraction operation Starting from Column 7 ? Do you know how many total Columns are present or is it dynamic ?

Can you maybe Show us an Expected Output Excel you are expecting based on the Input Data Sheet you have Provided ?

Those have about monthly payment, so it consists 24 column (to put currency), need to check the price gap, which indicate if the bill of previous or current already paid or not. Column1 consist of need-to-payColumn2 consist of the real-payment. With condition like this:
Column7 - Column8 != 0, give messages need-to-pay.

Thx for asking. @supermanPunch

@kristoff Ok. I guess the Calculation part that you have to do is based on Subtraction of each two Column values of a row starting from Column 7. But can you Show us the Output Format that you expect for that data?

@supermanPunch, I tried to subtraction the column that consist of currency by creating the nested for each row loops, but the second loop couldn’t working because the input I used for the second loop is DataRow. Now I need to assign this DataRow (by selecting only the currency) into DataTable. My expect output is got result of the substraction.

@kristoff Where do you want to Store this result ? Do you want it to be put into an Excel file ? How do you want to represent it?

1 Like

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