Reputation:
the error is on qRow. How can I fix this problem with linq? I have tried to find an answer to this with no luck.
IEnumerable<DataColumn> iCols = (from i in Interlocks
join r in Results on i.InterlockID equals r.InterlockID
where r.StationType.Equals("RT") && r.LineID.Equals("1") && r.TestNo == 1 && r.StationID == 1
&& i.SerialNumber.Equals("C11205150001") && (r.DateTested >= DateTime.Now.AddMonths(-48) && r.DateTested <= DateTime.Now)
select new { i.SerialNumber,i.ModelNumber,r.DateTested,r.InterlockID,r.ResultID,r.ProgramDescription,r.TestStatus,r.CycleTime}).Distinct().Cast<DataColumn>();
interlock.Columns.Add("SerialNumber",Type.GetType("System.String"));
interlock.Columns.Add("ModelNumber", Type.GetType("System.String"));
interlock.Columns.Add("DateTested", Type.GetType("System.DateTime"));
interlock.Columns.Add("InterlockID", Type.GetType("System.Int32"));
interlock.Columns.Add("ResultID",Type.GetType("System.Int32"));
interlock.Columns.Add("ProgramDescription",Type.GetType("System.String"));
interlock.Columns.Add("CycleTime", Type.GetType("System.Int32"));
interlock.Columns.AddRange(iCols.ToArray());
interlock.AcceptChanges();
foreach (DataRow qRow in interlock.Rows)
{
var details = (from d in qRow
join rd in Results_Details on d.ResultID equals rd.ResultID
select new {d.DateTested,d.ResultID,rd.ResultNameID,rd.ResultValue}).Distinct();
Upvotes: 1
Views: 2038
Reputation: 460158
A DataTable
is not strong typed, you need to use a DataRow
's Field extension or cast the objects accordingly.
from d in qRow
join rd in Results_Details on d.Field<String>("ResultID") equals rd.ResultID
Also remember to add a referenceto System.Data.DataSetExtensions.dll
and using System.Data;
as stakx has mentioned.
Upvotes: 1