How to get not equal to


#1

i have 2 excel sheets with
(sheet1) (sheet2)
empid name email empid name
123 abc abc@gmail 123 abc
345 def jkl@gmail 899 jkl
567 ghi ghi@gmail 567 ghi

i need to extract jkl@gmail.com from sheet2
i tried with not equal to(i.e < >) i got jkl along with that i got others names also


#2

Where are you using <>, whats is your condition? Comparing two sheets?


#3

you can compare two datatable rows with empid

if dt1 empid <> dt2 empid — get dt2.row(email)


#4

i am not getting its working same as <>


#5

ya comparing two sheets

sheet1
Empid Name
123 abc
234 def
345 ghi
sheet2
Empid Name
123 abc
234 def
678 xyz
890 sdf

output
Emp_id Name
678 xyz
890 sdf

if(dt1.row(0).toString<>dt2.row(0).toString) i didn’t get for isNot as well iam getting not matched value too


#6

if you want to compare rows, not the uniqye ids, you can do the following way

bool isRowEqual = rowDt1.ItemArray.SequenceEqual(rowDt2.ItemArray)


#7

I am not getting


#8

https://www.dotnetperls.com/datatable-compare-rows

Thanks,
Vinay


#9

Hello,

If you want to compare only empid then you need to target the ‘datacells’, on your if you just take the row themselves.

it should be : if(dt1.rows(0)(0).toString<>dt2.row(0)(0).toString) to get the first cell of the first row.
However, it is more suitable to do it inside a for each row using the variable “row” and taking its first children : row(0).tostring.

If you want to compare all the row then you should use Sequence equal as @vvaidya said.

In your case it would be Dt1.Rows(0).ItemArray.SequenceEqual(Dt2.Rows(0).ItemArray).

Cheers.


#10

Column Count won’t be same in my case :frowning:
Is there any way to find not equal values
sheet1
Empid Name 1 2
123 abc
234 def
345 ghi
sheet2
Empid Name Dept
123 abc
234 def
678 xyz
890 sdf
789 tyu

output
Emp_id Name
678 xyz
890 sdf
789 tyu