Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ DataTable #1's rows that are NOT present in DataTable #2 ♦
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Data; // aljodav // http://rextester.com/users/376 namespace Rextester { public class Program { public static DataTable GetDT1() { DataTable dt= new DataTable(); dt.Columns.Add("Code",typeof(string)); dt.Columns.Add("Name",typeof(string)); dt.Rows.Add("C30","Ray"); dt.Rows.Add("C3","Jim"); dt.Rows.Add("C35","Kim"); dt.Rows.Add("C1","Smith"); dt.Rows.Add("C2","Joan"); dt.Rows.Add("C8","Mae"); dt.Rows.Add("C39","Ryz"); dt.Rows.Add("C31","John"); dt.Rows.Add("C33","Tim"); dt.Rows.Add("C11","Crau"); dt.Rows.Add("C9","Leslie"); return dt; } public static DataTable GetDT2() { DataTable dt= new DataTable(); dt.Columns.Add("Code",typeof(string)); dt.Columns.Add("Name",typeof(string)); dt.Columns.Add("Phone",typeof(string)); dt.Columns.Add("Address",typeof(string)); dt.Rows.Add("C44","Ytrew","555","Austria"); dt.Rows.Add("C22","Zejn","666","China"); dt.Rows.Add("C3","Jim","777","Spain"); dt.Rows.Add("C1","Smith","111","France"); dt.Rows.Add("C55","Cramm","888","Russia"); dt.Rows.Add("C2","Joan","222","Wales"); dt.Rows.Add("C31","John","333","Australia"); dt.Rows.Add("C32","Luc","444","Greece"); return dt; } public static void Main(string[] args) { DataTable dt1= GetDT1(); DataTable dt2= GetDT2(); List<string> codes= dt2 // to be used in Where() LINQ statementq .AsEnumerable() .Select(x=>x.Field<string>("Code")) .ToList() ; codes.Sort(); // for BinarySearch Console.WriteLine("These are the DT1 rows that are NOT present in DT2:\n\nCode Name"); dt1 .AsEnumerable() .Where(x=>codes.BinarySearch(x.Field<string>("Code"))<0) .Select(x=>new{Code=x.Field<string>("Code"),Name=x.Field<string>("Name")}) .ToList() .ForEach(x=>Console.WriteLine("{0,4} {1}",x.Code,x.Name)) ; Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
SIN_in_Pow
Saga name NLog
extrefGenerate
tester of xpath
asxasdxsd
UPDJLJ87258 Orderby grouping understanding
book iequatable
Collection Basic
newMultQ working on more2
172