Input array is longer than number of column in this table

Hi UiPath Community



wrote a linq query to filter data from excel not able to fix the problem and understand it need help regarding it

Thank you in adavance

@madhavraichur25 as per the linq you have 11 columns in that datatable, however as per the error there are less columns.

Check you datatable once how many columns it have.

The error “Input array is longer than the number of columns in table” typically occurs when the number of values you are trying to add to a row in the dt_Output DataTable does not match the number of columns defined in the table.

In your LINQ expression, you’re selecting an array of values to add as a new row to dt_Output. The issue might be arising from a mismatch between the columns in dt_Output and the array you’re attempting to add.

Steps to resolve this:

  1. Verify the number of columns in dt_Output: Make sure dt_Output has the same number of columns as the array you’re trying to add. For example, if dt_Output has 11 columns, then the array {row(0).ToString, row(1).ToString, ..., DDate.ToString} should also have exactly 11 elements.

  2. Check column indexes: Ensure that the columns you are referencing in your row() index match the actual columns in the dt_Input DataTable. For example, if dt_Input has 12 columns, ensure that the columns you’re referencing (like row(0), row(1), etc.) are within that range.

  3. Fix the code:

    • Ensure the DDate.ToString value is correctly added to the array.
    • If you are adding a new column, ensure that the new column is also part of the dt_Output structure.

Example fix:

Assuming dt_Output has 12 columns, you can adjust your LINQ statement like this:

(
    From row In dt_Input
    Let InvDate = DateTime.ParseExact(row("Date Of Invite").ToString.Split("")(0).Trim, "MM/dd/yyyy", Globalization.CultureInfo.InvariantCulture)
    Let DDate = CInt(DateDiff(DateInterval.Day, InvDate, Now.Date))
    Where DDate Mod 7 = 0 AndAlso (DDate <> 7 AndAlso DDate <> 14 AndAlso DDate <> 0)
    Select dt_Output.Rows.Add({row(0).ToString, row(1).ToString, row(2).ToString, row(3).ToString, row(4).ToString, row(5).ToString, row(6).ToString, row(7).ToString, row(8).ToString, row(9).ToString, row(10).ToString, DDate.ToString})
).CopyToDataTable()

Additional Points:

  • The Split("") is likely incorrect because it splits the string by an empty character. If you’re intending to split the date, you might want to change this to Split(" ")(0) or another appropriate delimiter.
  • Ensure that the DDate calculation is correct and matches your business logic for filtering rows.

By ensuring that the number of elements in the array matches the number of columns in the destination DataTable, you should be able to resolve the error.