Compare the data

Hi,I want to compare whether the data read this time has the same number of rows as the data read last time, may I ask how to operate,thank you.

Hi @Chen-Jim

You may try save the current read data into a temp variable, then when read the next data, do a compare with current data and temp variable to see if current data is match with previous data.

Hope it helps.


Hi Allenliaw
Thanks for your help,and I have another question if the comparison data is performed under the condition of dowhile, the new data is the old data in the next loop, the new data needs to be compared with the old data, and so on, what should be done

Hi @Chen-Jim,

Sorry I am not too sure what do you mean.

Do you mean something like the below sample?


Where does your data come from? Read from excel? Web site?


Hi @Allenliaw ,
I’m sorry that I didn’t make it clear. The data is downloaded from the website, and every time the newly downloaded data needs to be compared with the existing excel data. After comparison, the non-repeated data will be recorded into the existing excel, and the data will be downloaded from the website for comparison every day.So I would like to ask how to cycle the comparison data?

Hi @Chen-Jim, I would suggest to use the Linq expression for comparing the previous data and current data and receive a boolean value as output.

Hi @Chen-Jim,

So from what you just said, your process looks like below?

  1. Have an existing excel file (old data)
  2. Download new excel file from the web (new data)
  3. Compare two excel files and find any new data
  4. For any non-repeated data will add to the current excel file from the new excel file that downloaded from the web

If this is how your process might be looks like, what you might be able to do is read both excel file and convert to datatables and loop through the datatables then compare data to see if any match, add all non-matched data to a new datatable then add to the old excel file after finish compare all data.

It’s bit hard to provide more information base on the information you have provided, if you can provide more details of your process, simple flow diagram, it might be helpful for people to provide better solutions or suggestions.


Hi ,
Can you write a demo for my reference?

Hi @Allenliaw ,
Just as you said,how to deal with this situation?

what is your current data type?

Hi ,
The data comes out of excel, so data type is datatable.

Why are you assigning it to integers then.

Sorry,I didn’t catch your meaning,I’m not assigning an integer,read excel and assigned it to datatable.

Hi @Chen-Jim,

What you might be able to do are:

  1. Convert the existing excel file to datatable (A).
  2. Download the new excel file and convert to datatable (B) with different name
  3. You can then use for each rows to compare both datatable, if there is any data not match, add it to the temp datatable, and at the end of the process append it to the existing datatable (A). There might be better way to compare the data which you can search the forum.

There might be an issue with your process, if you keep adding records to the existing excel file, your process will getting slower later when you have too many rows of data, you will need to workout this by yourself on how you want to resolve it.


use this
Datatable Final_result = (From x In dt1.AsEnumerable() where (From a In dt1.AsEnumerable() Join b In dt2.AsEnumerable() On a(“Controller”).ToString() Equals b(“Critical tags”).ToString() select a).Contains(x) select x).CopyToDataTable()

Scenario is fetch the tags data from excel1 column and find in excel2 in Controller column only.

Hi @Allenliaw ,
Thanks for your patient answer. At present, my solution is the same as what you described, but there will be another problem.
I tried to write a linq statement to deweight the data, but if the new data is exactly the same as the old data, an error was reported, because the different data could not be found.

Hi ,
I tried to write a linq statement myself based on your demo,but there will be another problem,if the new data is exactly the same as the old data, an error was reported, because the different data could not be found.This is screenshot,please give me some advise.%E3%82%AD%E3%83%A3%E3%83%97%E3%83%81%E3%83%A31

can you show the error message.

This is error message,because if the new data is exactly the same as the old data,the different data could not be found. %E3%82%AD%E3%83%A3%E3%83%97%E3%83%81%E3%83%A3

@Chen-Jim If you’re downloading fresh file alone for each run, you can do below steps.

  1. Read file and store in data table
  2. Calculate the count of the rows and store in a Asset or an master file
  3. While getting next run you can read the master file or asset and compare it with fresh file.