如何使用LINQ获取数据表值 [英] How to Get DataTables Value using LINQ

查看:69
本文介绍了如何使用LINQ获取数据表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是与c#中的DataTable相关的

我有两个数据表都具有一个普通的col.名称("PlkId"),
现在一个有100条记录,另一个表有50条记录,
表示剩下的50条记录实际上是Diff.记录,
我想将这50条记录存储在第三张表中?

我试过但未发生的使用LINQ(这更重要)

我使用dataTable.select()方法解决了这个问题,但想知道我们可以通过LINQ做到吗?

提前感谢:)

阿米特·辛格

Pune

My question is for DataTable Related in c#

I have two data Tables both are having One common col. name ("PlkId"),
now one is having 100 records and other Table is having 50 records,
means remain 50 records are Actually Diff. Records,
I would like to store that 50 records in third Table ?

USING LINQ ( this is more importent ) i tried but not happening

I solved it bu using dataTable.select() method but want to know that can we do it through LINQ ?

Thanx in Advance :)

Amit Singh

Pune

推荐答案

这里有一些通用的LINQ代码应该起作用(您必须用自己代码中的适当值替换列比较内容):

Here''s some generic LINQ code that should work (you have to replace the column comparison stuff with appropriate values from your own code):

var results = (from record in dataTable
               where record.column == somevalue
               select record).ToList();


...但是我不得不问-为什么当一个简单且可维护的非LINQ解决方案可以正常工作并且可能会更好地解决问题时,为什么要对LINQ感到困扰?如果这是用于工作项目,请关闭文件并继续执行下一个任务.


...but I have to ask - why bother with LINQ when a simple and maintainable non-LINQ solution works fine and will probably be better performing beisdes? If this is for a work project, close the file and move on to the next task.


这篇关于如何使用LINQ获取数据表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆