How to delete the row in datatable?

Hi all,

I need guidance on deleting rows in a DataTable where the first row contains the entry “log analyzer, intrusions”. Rows with “time” and “user” in the first column should remain unaffected. Your assistance is appreciated.

Thanks

Could you please elaborate your condition more. @chandu_royal

Hi @chandu_royal

If Possible,Can you Provide Sample Input and expected Output

I simply want to eliminate headers located in the middle of the DataTable.

@chandu_royal

try this ::

yourDataTable = yourDataTable.AsEnumerable().Where(Function(row) Not row.Field(Of String)(0).Equals("log analyzer, intrusions")).CopyToDataTable()

cheers…

If you know the row index, then it’s possible to delete that row by using the Remove Data Row activity.

Check the below image for better understanding,
image

In the RowIndex field provide the rowindex that you want to delete.
In the Datatable field provide the datatable where you want to delete.

Hope you understand!! @chandu_royal

Still remains the same.

I am reading 30 CSV files and appending them into a single Excel sheet. Within this process, I aim to remove the headers located in the middle of the DataTable.

Okay @chandu_royal

For that you can use the LinQ Expressions to delete the the row which contains “log analyzer, intrusions”.

yourDataTable = yourDataTable.AsEnumerable().Where(Function(row) Not row.Field(Of String)(0).Contains("log analyzer, intrusions")).CopyToDataTable()

Hope it helps!!

I have successfully removed rows containing “log analyzer” using the Filter DataTable activity. However, I am encountering difficulty deleting rows that contain headers like “time,” “value,” and “IP address” in the middle of the DataTable.

Additionally with this log analyzer, intrusions you want to delete the rows which contains time, value and IP Address right,

If yes, first create a List Variable and then use the below expressions.

- Assign -> Keyword = New List(Of String) From {"log analyzer, intrusions", "time", "value", "IP address"}

- Assign -> yourDataTable = yourDataTable.AsEnumerable().Where(Function(row) Not keywords.Any(Function(Keyword) row.Field(Of String)(0).Contains(keyword))).CopyToDataTable()

Hope it helps!!

Hi @chandu_royal ,
Could you please share input and expect output
We can delete by delete data row or filter…
regards,

Use the activity Filter Data Table. Configure the filter to remove rows where Column1 contains your unwanted text.

Hi @chandu_royal

  1. Read Range

  2. For Each Row
    If Condition - row(0).ToString.Contains(“log analyzer, intrusions”) AndAlso Not row(0).ToString.Contains(“time”) AndAlso Not row(0).ToString.Contains(“user”)

    Then
               Create a Var called rowToDelete List(Of DataRow)
                  rowToDelete.Add(row)  - Use activity called Append Item to Collection
    
  3. After Looping Use Invoke Method

  • TargetObject: Your DataTable variable
  • MethodName: “AcceptChanges”