Excluir linhas de uma tabela

Olá comunidade!

Preciso excluir linhas de uma tabela baseada em um array.
Por exemplo, tenho um array que contem as linhas a serem excluidas de um arquivo excel.

Conseguiriam me exemplificar uma forma de fazer isso?

@amanda.gondim

Welcome to the community

  1. Either use find/replace if you have a value which is unique to the row which will give the cell number then use it in delete rows
  2. Or read the data into datatable then use loop or filtering to filter for each datarow and findthe row index and use it

Cheerss

Olá amigo.

Me desculpe, os dados estão inseridos em uma DataTable.
Você acha que um JoinDataTable seria a solução?

Para exemplificar: Tenho a tabela 1 que contem todas as informações, inclusive a que preciso excluir. E a tabela 2 somente com os dados a serem excluidos. Preciso excluir as informações da tabela 1 baseado nas informações da tabela 2

Hi @amanda.gondim

  • Instead of removing the data in the existing data table, you can filter out the data and can get to new data table
  • As per my understanding, you want to remove the first data table data based on the second data table. If this is the scenario, you can use below exp
Variable of type FinalDT = DT.AsEnumerable.Where(Function(x) Not DT1.AsEnumerable.Where(Function(y) x(0).ToString.Equals(y(0).ToString)).Any).CopyToDataTable

Note:

  • Here, I’m comparing the first column of first data table (x(0)), with the first column of second data table (y(0)). You can change the column index accordingly, if first column it is X(0), second column it is x(1)…
  • If the first data table contains any values that second data table has, then those will be excluded and saving those to Final DT variable

Please check the attached workflow

SampleWorkflow.zip (3.3 KB)

@amanda.gondim

If that is the case then you can use except function to remove the matched rows from table1

Dt1 = dt1.AsEnumerable.Except(dt2.AsEnumerable,System.Data.DataRowComparer.Default).CopyToDataTable

Using join youcan get matched values but not un matched…the above eill compare whole row not only a single column…if you need to compare based on single column then let me know there are other ways

Hope this helps

Cheers

Não conseguir obter o resultado usando seu exemplo, pois tenho que considerar outras métricas.

eu tenho um assign que obtem as linhas, gostaria de usar a mesma expressão linq, porem excluindo essas linhas.

o assign que estou usando

dt = dt.AsEnumerable.Take(contadorLinhas).CopyToDataTable

Também não conseguir obter o resultado usando seu exemplo, pois tenho que considerar outras métricas.

eu tenho um assign que obtem as linhas, gostaria de usar a mesma expressão linq, porem excluindo essas linhas.

o assign que estou usando

dt = dt.AsEnumerable.Take(contadorLinhas).CopyToDataTable

ao invés de usar take, queria excluir esse “contadorLinhas”

@amanda.gondim

If you want to delete any lines then use skip instead of take in the same

Cheers

olá amigo!

infelizmente não obtive sucesso :frowning:

@amanda.gondim

Can you explain what you tried and what you did not succeed in? That way we can help better

Cheers

Olá!

Claro. Segue o fluxo de trabalho.