LINQ Code Isse

Hi…

I need to check dt1 datatable value on the bases of columns if any cell is null or empty. it has to pick the value from dt2 on based.

Both dt1 and dt2 having unique columns Name.

i got the error on below code… i dont know to fix it.

(from i in Enumerable.Range(0, {dtData1.Rows.Count, dtData2.Rows.Count}.Min())
let r1 = dtData1.Rows(i)
let r2 = dtData2.Rows(i)
let arrNames = dtData1.Columns.Cast(Of DataColumn).Select(function (c) c.ColumnName).toArray
let ra = arrNames.Select(function (x) if (dtData2.Columns.Contains(x), r2(x), r1(x))).toArray
Group Join dtData2 in dtData2.AsEnumerable on dtData1(0) Equals dtData2(0) into gp=Group
from g in gp.DefaultIfEmpty
Select ra = new object () {}
Select dtResult.Rows.Add(ra)).CopyToDataTable()

Plz check and correct

Thanks
Shyam

which error

Hi @ppr

Error Screen shot

image

Thanks
Shyam

the join / Group join LINQ syntax has some contraints. It is expecting to loop over two collections

first looped collection is the index sequence: From i in …
second looped collection is what we do find after Group Join…

on the join condition the left side / right is to mention, we do see this complained by the error

However there are several parts in the presented LINQ statements which are risking to fail.

We would suggest to share with us:

input sample data
Case description
expected output sample

Based on this we can look for solution approach options

Hi @ppr

check all details in input file if any cell is empty. i have master data in All_Details file

this two file are compare and fill data if anything is empty.

Please refer Expected Output file for your reference.

Input.xlsx (13.5 KB)

All_Details.xlsx (26.7 KB)

Expected_Output.xlsx (13.8 KB)

Thanks
Shyam

A few questions left but give a try on followoing:

Assign Activity
dtResult = dtInput.Clone

Assign Activity
dtResult =

(From d1 In dtInput.AsEnumerable
Where d1.ItemArray.Any(Function (x) isNothing(x) OrElse String.IsNullOrEmpty(x.toString.Trim))
Let d2m = dtAllDetails.AsEnumerable.Where(Function (d2) d1(0).toString.Trim.Equals(d2(0).toString.Trim)).FirstOrDefault
Where Not isNothing(d2m)
Let ra = d2m.ItemArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

when dInput has blanks we will take dMaster when it was found

Hi @ppr

i got error… ItemArray is not member of System.Data.Table.

image

Thanks
Shyam

Where.d1.ItemArray vs Where dtInput

image

sorry, had fixed the statement and did the correction on the above post. It was validating.

Hi @ppr

i got error…

can you tell me how to this code without Build Datatable.

how to do it based on columns Name if matches only can do other give default value.?

Thanks
Shyam

@Shyam_Pragash

Did you save the output of Read Range activity in dtInput variable ? And also checked Add Headers option in it ?

Hi @lakshman

i check i change some query it working fine…

But i have one issue…

unable to get all the columns name with value in dtinput

it give output dtinput and alldetails datatable matching columns values only…

How to get other columns ?

Thanks
Shyam

Hi @ppr

unable get all the value in dtinput file…

dtinput file totaly 30 rows after runing this code i got only 20 rows…

why ?

Thanks
Shyam

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.