Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Compare Two Data Tables Using Linq in Asp.net

DZone's Guide to

How to Compare Two Data Tables Using Linq in Asp.net

A code snippet to compare two data tables using Linq in Microsoft's .NET language.

· Database Zone ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

This article is used to get different records from datatable1 compared with datatable2 using LINQ Query.  This mismatched record gets from another data-table. 

Query

var record1 = datatable1.AsEnumerable().Select(a => new {              

                  matchColumnValue = a["columnName"].ToString() });

var record2 = datatable2.AsEnumerable().Select(b => new {

                   matchColumnValue = b["columnName"].ToString() });

var exceptTotalRecord = record1.Except(record2);

DataTable datatableFinal = (from a in exceptDirectFare.AsEnumerable()

  select a).CopyToDataTable();


  


Get comfortable using NoSQL in a free, self-directed learning course provided by RavenDB. Learn to create fully-functional real-world programs on NoSQL Databases. Register today.

Topics:
asp net

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}