Datarow extraction issue

Hi All,

Here I have a datatable named ReportDT and have 2 string variable values.
Variable names are var1, var2

I need to get the row index of ReportDT where the first column value matches with var1 and second column value matches var2.

For this I have tried the following expression
ReportDT.Rows.IndexOf(ReportDT.AsEnumerable.Where(Function(r) r(“Candidate_Number_from_Reference_Excel”).ToString=var1 AndAlso r(“Centre_Number”).ToString = var2.FirstOrDefault)

but when I tried this expression, I’m getting an error like the below one
image

can anyone help me with this?
Thanks in advance

@rnahasnahasuddin

You need to close the Bracket after var2

var2)().firstorDefault)

I have tried this but it doesn’t work.

this is my correct expression:
ReportDT.Rows.IndexOf(ReportDT.AsEnumerable.Where(Function(r) r(“Candidate_Number_from_Reference_Excel”).ToString=CurrentRow.Item(4).ToString AndAlso r(“Centre_Number”).ToString = CurrentRow.Item(2).ToString).FirstOrDefault)

can you please check?

ReportDT.Rows.IndexOf(ReportDT.AsEnumerable.Where(Function(r) r(“Candidate_Number_from_Reference_Excel”).ToString.equals(CurrentRow.Item(4).ToString) AndAlso r(“Centre_Number”).ToString.equals(CurrentRow.Item(2).ToString))().FirstOrDefault)

Hey @rnahasnahasuddin

Whenever we are dealing with Equals, We should always use Trim Function.

ReportDT.Rows.IndexOf(ReportDT.AsEnumerable.Where(Function(r) r("Candidate_Number_from_Reference_Excel").ToString.Trim.Equals(CurrentRow(4).ToString.Trim) AndAlso r("Centre_Number").ToString.Trim.Equals(CurrentRow(2).ToString.Trim)).FirstOrDefault)

Screenshot for your reference:

Above LinQ will solve your query!

Regards,
Ajay Mishra