简体   繁体   English

数据表连接 c# - 连接数据表

[英]DataTable joins c# - joins on datatable

How to use joins with dataTable?如何将连接与 dataTable 一起使用? Since i am new to C#, I dont know why my code is not working.由于我是 C# 的新手,我不知道为什么我的代码不起作用。 can anyone please look into this?有人可以调查一下吗?

var result = from x in clientpos.AsEnumerable()
                     join y in exec_pos.AsEnumerable()
                     on new { X1 = x.Field<string>("ClientCode"), X2 = x.Field<string>("Symbol"),
                         X3 = x.Field<string>("Expirydate"), X4 = x.Field<string>("Strikeprice") , X5 = x.Field<string>("ClientCode") }
                     equals new { X1 = y.Field<string>("ClientCode"), X2 = y.Field<string>("Symbol"),
                         X3 = y.Field<string>("Expirydate"), X4 = y.Field<string>("Strikeprice") ,
                         X5 = y.Field<string>("ClientCode")
                     }
                     select x;

The join is in the format below.联接采用以下格式。 You can add addition WHERE to the query if you need to additional filtering.如果您需要额外的过滤,您可以在查询中添加额外的 WHERE。

var result = (from x in clientpos.AsEnumerable()
             join y in exec_pos.AsEnumerable() on x.Field<string>("ClientCode") equals y.Field<string>("ClientCode")
             select new { client = x, exec = y}).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM