Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 18, 2012 01:28 PM by bruce (sqlwork.com)
Member
218 Points
152 Posts
Apr 18, 2012 01:01 PM|LINK
Ive done this lots of times but this time i am struggling
the error is at the part new Lists.lGrid { .......... };
public List<Lists.lGrid> theGrid(List<Lists.lFirms> lfirm, List<Lists.lCRMProgress> lprogress) { var grid = from f in lfirm join p in lprogress on f.id equals p.firmid into l_f from p in l_f.DefaultIfEmpty() select new Lists.lGrid { address1 = f.address1, address2 = f.address2, address3 = f.address3, address4 = f.address4, country = f.country, createddate = f.createddate, email = f.email, faxno = f.faxno, firmid = f.id, id = f.id, firmsize = f.firmsize, firmsizeid = f.firmsizeid, isaccountancy = f.isaccountancy, lastbooking = f.lastbooking, lastevent = f.lastevent, lasteventafterst = f.lasteventafterst, logo = f.logo, modifieddate = f.modifieddate, monthcount = f.monthcount, monthspend = f.monthspend, name = f.name, postcode = f.postcode, programformatid = f.programformatid, quartercount = f.quartercount, quarterspend = f.quarterspend, sector = f.sector, sectorid = f.sectorid, smartplanexpiry = f.smartplanexpiry, spactive = f.spactive, STActive = f.STActive, stexpirydate = f.stexpirydate, telno = f.telno, totalcount = f.totalcount, totalspend = f.totalspend, webplanexpiry = f.webplanexpiry, websiteurl = f.websiteurl, wpactive = f.wpactive, yearcount = f.yearcount, yearspend = f.yearspend, uid = p.uid, crmstatus = p.crmstatus == null ? "New" : p.crmstatus, crmstatusid = p.crmstatusid , crmtype = p.crmtype == null ? "" : p.crmtype, crmtypeid = p.crmtypeid , reviewdate = p.reviewdate == null ? Convert.ToDateTime("2000-01-01 00:00:00") : p.reviewdate, updatedate = p.updatedate == null ? Convert.ToDateTime("2000-01-01 00:00:00") : p.updatedate, username = p.updatedate == null ? "None" : p.username }; return grid.ToList<Lists.lGrid>(); }
270 Points
50 Posts
Apr 18, 2012 01:03 PM|LINK
ArchieEric return grid.ToList<Lists.lGrid>()
before this check for grid is not null.
Apr 18, 2012 01:04 PM|LINK
its not null, lfirm is packed with data
and it doesnt get that far
291 Points
116 Posts
Apr 18, 2012 01:15 PM|LINK
cause of this error is empty datasource
Contributor
6445 Points
1187 Posts
Apr 18, 2012 01:19 PM|LINK
Some selected field is null. You should probably add some more NULL checks like the ones for the reviewdate and updatedate fields.
All-Star
36904 Points
5452 Posts
Apr 18, 2012 01:28 PM|LINK
you performed a left join, so p can be null, thus any reference to p.??? can fail. your null handling logic is wrong. it shoudl be:
crmstatus = (p == null || p.crmstatus == null) ? "New" : p.crmstatus,
....
ArchieEric
Member
218 Points
152 Posts
Object reference not set to an instance of an object
Apr 18, 2012 01:01 PM|LINK
Ive done this lots of times but this time i am struggling
the error is at the part new Lists.lGrid { .......... };
public List<Lists.lGrid> theGrid(List<Lists.lFirms> lfirm, List<Lists.lCRMProgress> lprogress) { var grid = from f in lfirm join p in lprogress on f.id equals p.firmid into l_f from p in l_f.DefaultIfEmpty() select new Lists.lGrid { address1 = f.address1, address2 = f.address2, address3 = f.address3, address4 = f.address4, country = f.country, createddate = f.createddate, email = f.email, faxno = f.faxno, firmid = f.id, id = f.id, firmsize = f.firmsize, firmsizeid = f.firmsizeid, isaccountancy = f.isaccountancy, lastbooking = f.lastbooking, lastevent = f.lastevent, lasteventafterst = f.lasteventafterst, logo = f.logo, modifieddate = f.modifieddate, monthcount = f.monthcount, monthspend = f.monthspend, name = f.name, postcode = f.postcode, programformatid = f.programformatid, quartercount = f.quartercount, quarterspend = f.quarterspend, sector = f.sector, sectorid = f.sectorid, smartplanexpiry = f.smartplanexpiry, spactive = f.spactive, STActive = f.STActive, stexpirydate = f.stexpirydate, telno = f.telno, totalcount = f.totalcount, totalspend = f.totalspend, webplanexpiry = f.webplanexpiry, websiteurl = f.websiteurl, wpactive = f.wpactive, yearcount = f.yearcount, yearspend = f.yearspend, uid = p.uid, crmstatus = p.crmstatus == null ? "New" : p.crmstatus, crmstatusid = p.crmstatusid , crmtype = p.crmtype == null ? "" : p.crmtype, crmtypeid = p.crmtypeid , reviewdate = p.reviewdate == null ? Convert.ToDateTime("2000-01-01 00:00:00") : p.reviewdate, updatedate = p.updatedate == null ? Convert.ToDateTime("2000-01-01 00:00:00") : p.updatedate, username = p.updatedate == null ? "None" : p.username }; return grid.ToList<Lists.lGrid>(); }kimkosta06
Member
270 Points
50 Posts
Re: Object reference not set to an instance of an object
Apr 18, 2012 01:03 PM|LINK
before this check for grid is not null.
ArchieEric
Member
218 Points
152 Posts
Re: Object reference not set to an instance of an object
Apr 18, 2012 01:04 PM|LINK
its not null, lfirm is packed with data
and it doesnt get that far
Shoaib Rashi...
Member
291 Points
116 Posts
Re: Object reference not set to an instance of an object
Apr 18, 2012 01:15 PM|LINK
cause of this error is empty datasource
mm10
Contributor
6445 Points
1187 Posts
Re: Object reference not set to an instance of an object
Apr 18, 2012 01:19 PM|LINK
Some selected field is null. You should probably add some more NULL checks like the ones for the reviewdate and updatedate fields.
bruce (sqlwo...
All-Star
36904 Points
5452 Posts
Re: Object reference not set to an instance of an object
Apr 18, 2012 01:28 PM|LINK
you performed a left join, so p can be null, thus any reference to p.??? can fail. your null handling logic is wrong. it shoudl be:
....