Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am having two datatable from excel ,Here I want to search the data from first datattable and check for the availability in second table ,If it available then want to add a new column in first datatable and want to set the value as present

What I have tried:

I have created two datatable and tried using Linq but don't know how to implement it
Posted
Updated 15-May-18 23:30pm

1 solution

We can't give you a solution to this: it depends on the data primarily, and the column organisation.

Start by looking at your two data sources: identify which columns you need to work with and which define "availability", and work out exactly how you tell a row is "available". When you know that, you can start looking at finding them.

Actually doing it is pretty easy: write a method that accepts a row and checks it for "availability" - you can then use Linq (if you want to) to process all the rows from Table1 and build a collection of rows which are available.
C#
var available = myDataTable.AsEnumerable().Select(r => IsAvailable(r));


But ... "add a new column in table 1" is a bit odd - you don't want to do that for every "available row", or do you? I'd suggest that you need to think a bit more carefully about exactly what you are trying to achievedatatable
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900