linq to SQL查询执行 [英] linq to SQL query execuation

查看:116
本文介绍了linq to SQL查询执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataTable dt = db.CustomerMasters.OrderBy(x => x.CustName); 


不支持如何将其转换为数据表?


is not supporting how to convert it to data table???

推荐答案

您可以尝试以下解决方案.

Hi you can try the below solution.

IEnumerable<DataRow> query = db.CustomerMasters.OrderBy(x => x.CustName) 
//Create a table from the query.
DataTable boundTable = query.CopyToDataTable<DataRow>();



或检查此链接

http://stackoverflow.com/questions/4460654/best-practice-convert-linq-query-result-to-a-datatable-without-looping [



or check this link

http://stackoverflow.com/questions/4460654/best-practice-convert-linq-query-result-to-a-datatable-without-looping[^]

//Edits to merge two answers into one and to clean up code paste issues - TimCorey


请参考:
http://msdn.microsoft.com/en-us/library/bb386921.aspx [ ^ ]
从查询创建数据表(LINQ到数据集)

http://msdn.microsoft.com/en-us/library/bb387004.aspx [ ^ ]
该链接提供了有关使用LINQ to DataSet进行编程的概念性信息和示例.

http://msdn.microsoft.com/en-us/library/bb669096.aspx [ ^ ]
本主题描述了如何实现两个自定义的CopyToDataTable< t>.扩展方法接受DataRow以外类型的通用参数T.
Please refer:
http://msdn.microsoft.com/en-us/library/bb386921.aspx[^]
Creating a DataTable From a Query (LINQ to DataSet)

http://msdn.microsoft.com/en-us/library/bb387004.aspx[^]
This link provides conceptual information and examples for programming with LINQ to DataSet.

http://msdn.microsoft.com/en-us/library/bb669096.aspx[^]
This topic describes how to implement two custom CopyToDataTable<t> extension methods that accept a generic parameter T of a type other than DataRow.


这篇关于linq to SQL查询执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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