gpt4 book ai didi

asp.net - 无法转换类型为“System.Collections.Generic.List”的对象

转载 作者:行者123 更新时间:2023-12-02 05:04:00 25 4
gpt4 key购买 nike

我收到这个错误

Unable to cast object of type 'System.Collections.Generic.List`1[TransTripLeg]' to type 'System.Data.DataTable'.

我似乎无法弄清楚如何解决它。错误发生在下面代码中的 DataTable dtTable = 处。

if (!string.IsNullOrEmpty(Request.QueryString["EditMode"]))
{
DataTable dtUpdate = (DataTable)Session["TripRecords"];
DataRow[] customerRow = dtUpdate.Select("LegID = '" + sLegID.ToString() + "'");

我想我正在将它强制转换为 DataTable 类型,但我仍然收到错误。

最佳答案

你需要投Session["TripRecords"]List<TransTripLeg>而不是 DataTable

var collection = (List<TransTripLeg>)Session["TripRecords"];
var legs = collection.Where(c => c.LegID == sLegID);

关于asp.net - 无法转换类型为“System.Collections.Generic.List”的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16553285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com