0

我有一个从带有 LINQ 的内部连接表中选择的结果集。我怎样才能将结果集作为数据表返回?

DataProviderDataContext db = new DataProviderDataContext();

IEnumerable<DataRow> asd = (IEnumerable<DataRow>)(from dsa in (from usrAddr in db.T_USER_ADDRESSes join usr in db.T_USERs on usrAddr.USER_ID equals usr.USER_ID where usr.USER_ID == UserID select new { usr.REALNAME, usrAddr.USER_ID, usrAddr.USER_ADDRESS_ID, usrAddr.ADDRESS, usrAddr.TITLE, usrAddr.IS_DELIVERY, usrAddr.IS_INVOICE }).AsEnumerable() select dsa);

DataTable dt = asd.CopyToDataTable<DataRow>();

最好的祝福。

4

2 回答 2

1

不幸CopyToDataTable<DataRow>()的是,在IEnumerable<DataRow>. 您需要按照此处所述粉碎返回的数据:http: //msdn.microsoft.com/en-us/library/bb669096.aspx

于 2012-05-02T11:38:58.597 回答
0

我很惊讶DataTable dt = asd.CopyToDataTable<DataRow>();没有为你做这项工作。

尝试:

asd.CopyToDataTable(dt, LoadOption.PreserveChanges);
于 2012-05-02T11:33:53.790 回答