Reputation: 2982
I am getting this error
Unable to cast object of type 'System.Collections.Generic.List`1[TransTripLeg]' to type 'System.Data.DataTable'.
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.
Upvotes: 2
Views: 19441
Reputation: 583
Remove this symbol just works for me(') this works fine for me
DataRow[] dr = allleaveDt.Select("EmployeeId=" + empId);
Upvotes: 1
Reputation: 62301
You need to cast Session["TripRecords"]
to List<TransTripLeg>
instead of DataTable
var collection = (List<TransTripLeg>)Session["TripRecords"];
var legs = collection.Where(c => c.LegID == sLegID);
Upvotes: 4