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

Learn how our document data model can map directly to how you program your app, and native database features like secondary indexes, geospatial and text search give you full access to your data. Brought to you in partnership with MongoDB.

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();


  


Discover when your data grows or your application performance demands increase, MongoDB Atlas allows you to scale out your deployment with an automated sharding process that ensures zero application downtime. Brought to you in partnership with MongoDB.

Topics:
asp net

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}