List<T> joins DataTable

sothun.thay

New member
Joined
Oct 5, 2020
Messages
2
Programming Experience
Beginner
I have a List of objects (lst) and DataTable (dt). I want to join the lst and dt on common field (code as string) and need to return all matching rows in the lst.

My List<T> contains:

code name
1 x
2 y
3 z

The DataTable contains:
code value
3 a
4 b
5 c


the result is:
3 z

I would be much appreciated if you could help me resolve this problem.
 
Welcome to the forums.

This is homework, so can you show us what you've tried, thought of, or concluded, and show us where you are stuck?
 
Welcome to the forums.

This is homework, so can you show us what you've tried, thought of, or concluded, and show us where you are stuck?
Dear Sleepings

Thanks for getting back to me. Below is my code but it is not correct as i can't get the right statement:
C#:
var bd = from b in lst
         join d in dt.AsEnumerable() on b.code equals d.code
         select new { b.code, b.name };
Please help correct it.
 
Last edited by a moderator:
You need to provide a FULL and CLEAR explanation of the problem. That must include exactly what you're trying to achieve, how you're trying to achieve it and what happens when you try. Post #1 contains the first part and post #3 contains some of the second part. We need the rest of the second part and the third part. Also, please format code appropriately for readability. I have done it for you this time.
 
Back
Top Bottom