I have two big datatables. Both the datatables contains column “NotificationNo”
I want to filter second datatable -.
Condition → Only Same Notifications are acceptable. So Different notifications are not needed.
Note : I cannot use for each row loop as it will take too much time for processing.
DT1 as below
NotificationNo Validity Status
123 Yes Open
456 No Closed
789 Yes Open
DT2 as below
notificationNo ID
456 23
658 34
Then,requirement is to filter on datatable DT2 which will return me row of 456. As it is the only notification no which matches with notification no of DT1.
I am not finding an way to filter like this.
dtFiltered = (From p In dt1.Select
Select If((From q In dt2.Select
Where Convert.ToString(p("NotificationNo")).Equals(Convert.ToString(q("NotificationNo")))
Select q).ToArray.Count>0,(From q In dt2.Select
Where Convert.ToString(p("NotificationNo")).Equals(Convert.ToString(q("NotificationNo")))
Select q).ToArray.CopyToDataTable,New DataTable)).ToList.SelectMany(Function(x) x.Select).ToArray.CopyToDataTable.DefaultView.ToTable(True,(From p In dt2.Columns.Cast(Of System.Data.DataColumn) Select Convert.ToString(p.ColumnName)).ToArray)
Better you take first Distinct Values from dt1
dtFiltered Will be your Output.
Try this Query. I have not tested the Code
Worked Perfectly! No I was using distinct values only but it was giving same row for three times. After using your updated code i got the required result.
dtFiltered=If((From p In dt1.Select
Select If((From q In dt2.Select
Where Convert.ToString(p("Notification")).Equals(Convert.ToString(q("Notification")))
Select q).ToArray.Count>0,(From q In dt2.Select
Where Convert.ToString(p("Notification")).Equals(Convert.ToString(q("Notification")))
Select q).ToArray.CopyToDataTable,New DataTable)).ToList.SelectMany(Function(x) x.Select).ToArray.Count>0,(From p In dt1.Select
Select If((From q In dt2.Select
Where Convert.ToString(p("Notification")).Equals(Convert.ToString(q("Notification")))
Select q).ToArray.Count>0,(From q In dt2.Select
Where Convert.ToString(p("Notification")).Equals(Convert.ToString(q("Notification")))
Select q).ToArray.CopyToDataTable,New DataTable)).ToList.SelectMany(Function(x) x.Select).ToArray.CopyToDataTable.DefaultView.ToTable(True,(From p In dt2.Columns.Cast(Of System.Data.DataColumn) Select Convert.ToString(p.ColumnName)).ToArray),New DataTable)