无法投类型的对象'System.Collections.Generic.List [英] Unable to cast object of type 'System.Collections.Generic.List
本文介绍了无法投类型的对象'System.Collections.Generic.List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误
无法投类型的对象
System.Collections.Generic.List`1 [TransTripLeg]'
键入System.Data.DataTable。
Unable to cast object of type 'System.Collections.Generic.List`1[TransTripLeg]' to type 'System.Data.DataTable'.
和我似乎无法弄清楚如何解决它。在出现的错误的DataTable dtTable =
在下面的code。
and I can't seem to figure out how to resolve it. The error occurs at DataTable dtTable =
in the code below.
if (!string.IsNullOrEmpty(Request.QueryString["EditMode"]))
{
DataTable dtUpdate = (DataTable)Session["TripRecords"];
DataRow[] customerRow = dtUpdate.Select("LegID = '" + sLegID.ToString() + "'");
我想我浇铸输入数据表,但后来我仍然得到错误。
I think I am casting it to type DataTable, but then I still get the error.
推荐答案
您需要转换会话[三precords]
到列表< TransTripLeg>
而不是数据表
var collection = (List<TransTripLeg>)Session["TripRecords"];
var legs = collection.Where(c => c.LegID == sLegID);
这篇关于无法投类型的对象'System.Collections.Generic.List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文