Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using Linq to SQL to get some data so I can highlight a day on a calendar control where a record exists based on the date that record was added to the database.

There is a field in my database (datestamp) of data type date.

I am declaring an IEnumerable to achieve this as below:

Private unapprovedFireDays As IEnumerable(Of DateTime) = Nothing

My code in the page_prerender event to get the data can be seen below:

If calFire.VisibleDate.Year <> 1 Then
        baseDate = calFire.VisibleDate
    Else
        baseDate = DateTime.Now
    End If

    startDate = New DateTime(baseDate.Year, baseDate.Month, 1)
    endDate = startDate.AddMonths(1).AddDays(-1)


    Dim fdc As New FireAlarmDataContext()


    unapprovedFireDays = (From f In fdc.FireAlarms _
                          Where f.DateStamp <= endDate And _
                          f.DateStamp >= startDate And _
                          f.SupervisorChecked = "0" _
                          Order By f.DateStamp _
                          Select New DateTime(f.DateStamp.year, _
                                              f.DateStamp.month, _
                                              f.DateStamp.day) Distinct).ToArray()

For some reason, i'm getting blue lines under the f.datestamp.year, f.datestamp.month and f.datestamp.day items of code. If I hover over this it says 'Year' is not a member of 'Date?'

I have virtually identical code working with another table using a field in that table called datestamp of data type date and that works fine.

I am unsure why it thinks year should be a member of Date? and not Date. Have I missed something obvious?

share|improve this question

1 Answer

up vote 1 down vote accepted

I suspect the problem is quite simple.

'Year' is not a member of 'Date?' (a nullable type), it is a member of 'Date'.

I wonder if putting 'f.DateStamp.Value.Year' instead of 'f.DateStamp.year' would solve the problem?

share|improve this answer
Thanks debater this worked. Very strange though as x.datestamp.year works fine with another ienumerable I am using in the same sub. – Jimsan 20 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.