Hello Everyone,

I am having a hard time learning LINQ. I hope someone can here can
help me solve the problem or suggest a more appropriate forum for my
question.

The  Page_Load event attempts to bind the result of my query to a
gridview (grdTest). I think I am close to getting it, but I keep
getting an exception.

>>>>Exception Details: System.NullReferenceException: Object reference not set 
>>>>to an instance of an object.

I have tried binding grdTest to both of the lists that I am trying to
join. It works with both the "members" list and the "dates" list. What
is also interesting is that I get a result (but not the result that I
want) when I change the 3rd line of "query" to:

"on d.Date.Year equals m.colDateOfBirth.Value.Year"

so obviously, the equals test fails otherwise. The "members" list has
3 records, each of these with dates that made the dates in the "dates"
list.

The book I am using to teach myself is not very helpful.

Thanks in advance for any help or advice,

Paul

protected void Page_Load(object sender, EventArgs e)
 {

        System.Collections.Generic.List<P4.tblClient> members =
P4.tblClient.SelectTest();
        System.Collections.Generic.List<DateTime> dates = new
System.Collections.Generic.List<DateTime>();
        DateTime start = new DateTime(1963, 6, 1);

        while (start.Month.Equals(6))
        {
            dates.Add(start);
            start = start.AddDays(1);
        }

        var query = from d in dates
                    join m in members
                    on d.Date equals m.colDateofBirth into dm
                    from m in dm.DefaultIfEmpty()
                    select new { d.Date, m.colDateofBirth,
m.colFirstName, m.colLastName };


        grdTest.DataSource = query;
        grdTest.DataBind();
}


Reply via email to