using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace console_poc { class Program { static void Main(string[] args) { List<Entity> lstDBData = new List<Entity>(); // fetch all the db data from that table which u want to compare and store it in a list // or a datatable for LINQ i have used List<T> List<Entity> lstUploadData = new List<Entity>(); // store the excel upload data in this list List<Entity> lstDataWhichExistsInDb = new List<Entity>(); // this list will store the data which is available in the db List<Entity> lstDataWhichDoesNotExistsInDb = new List<Entity>(); // this list will store the data which is not available in the db // processs.. // storing the existing db data in one list and new value in another list lstUploadData.ForEach(k => { var item = lstDBData.FirstOrDefault(l => l.Column1 == k.Column1 && l.Column2 == k.Column2); if (item == null) lstDataWhichDoesNotExistsInDb.Add(k); else lstDataWhichExistsInDb.Add(k); }); // now based on ur requirement u can use which list u want.. } } public class Entity { public string Column1 { get; set; } public string Column2 { get; set; } } }
Datarow[] Dr = Datatable1.Select(" Name='Value 1' or Name='Value2'");//replace "Value 1" & "Vaue 2" with your value if(Dr.Length > 0) { //Means Record Exists } else { //Else Not }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)