How to change value of existing row and column in a data table

change the value of existing row belonginging to a particular column .and not adding data row.but changing existing value of a datatable

2 Likes

Here is a basic example on how to change the value of an existing row:
example.xaml (11.6 KB)

5 Likes

Hi Thanks a lot.and also can you help based on if condition then I have to change the value of only those row.how can we do it?

Hi!
You can use a For each row activity and then a If with your condition.
There are several examples in posts here. Just search “Filter datatable” or “Filter excel” and you will find plenty.

It depends on your condition really. For example you can check if the datatable is not null isNothing(yourdatatable) first and then iterate through all the rows and have another condition with some other actions.

If you have a specific condition maybe I can answer more specific.

Thanks a lot.it worked!

An even quicker method can be to use “DataTable”.Rows.IndexOf(“DataTable”.Rows.Find(“String”)) to find the first occurrence of a string. Removed the lengthy iteration through all rows. But I believe this only works if there was a primary key defined for the DT.

5 Likes

Hi!
I would like to know how to change the value contained in a datatable always in the same column, that is, for this column in each line whenever the text starts with TRF DE wanted to be only the text that appears after TRF DE. How can I do this?

Hi @miguel

This can be done likes this:

  1. Use For Each Row activity to loop through all rows in your Data Table
  2. Inside the loop, use this Assign activity
    row.Item("columnName") = row.Item("columnName").ToString.Replace("TRF DE", "")

This should loop through all the rows and replace all instances of TRF DE in your desired column with blank (effectively leaving only what is after) :slight_smile:

12 Likes

I get it!

I used 4 assign and it works!

Thanks for the help!!

Best regards,

1 Like

Hi,

I would like to match the text of column 0 (Descrição) in the “Consulta Movimentos” Sheet with the text from column 2 (Nome 1) in the “DadosSAP” Sheet. The problem is that the texts are not the same, only part of them. Is there any way to do this match and extract from the “DadosSAP” sheet the information from columns 0 and 1 to fill in the “Consulta Movimentos” sheet in columns 2 (Nº SAP) and 3 (Gestor(a))?

Best regards,

cid:image002.gif@01D47C35.7E4FFFF0

Could you give closer example of similarities between the columns. I get what you are trying to do, but I cannot see the matches between the columns you want to compare :slight_smile:

For example, you could try .Contains method to see if one string contains the other, like this:
stringNome1.Contains(stringDescrição) → this will return True or False

But of course it depends on the similarity between the values in the columns :slight_smile:

Hi Christian,

  1. Can we use AND condition to find the indexOf function if I have two mandatory column to check for finding the data.
  2. even after finding the index how to update it with another value?for that any other alternative is there apart from for each?

Hi, Can we do the Same without Looping?

Hi @akgurram

Yes, you can access specific elements like this:

youDataTable.Rows(0).Item("columnName")
7 Likes

Thank you. This really helped me!

1 Like

I have fetched the data from a PDF file a name and a usage charge. I want to compare that name from the names I have in the excel sheets if it is present in the excel sheet then I want to change the usage charge cell of that name only.
Kindly help me on this one.

Hi. What is TRF DE?

youDataTable.Rows(0).Item(“columnName”)

HI @loginerror

your this assign value youDataTable.Rows(0).Item(“columnName”)

how would you update if you do not know that … row-array value?

Let say you have 100 row and you want to update one row of them? how would you do that

Hi @loginerror you could suggest me how to do the same thing but with linq query???

Thanks in advance

HI,
U Have a linq query???