none
How do I get date parts in a dynamic query? RRS feed

  • Question

  • I have a large dynamic query.  Here is a much shortened version:

    Dim db As New InmProfilesDataContext
    Dim InmProfile = db.pr_members.AsQueryable

    InmProfile = InmProfile.Where(Function(post) (post.Suspend = False))
    If upperage.Text <> "99" Then
        InmProfile = InmProfile.Where(Function(post) (post.DATE_OF_BIRTH >= DateTime.Now.AddYears(0 - CInt(upperage.Text))))
    End If
    If lowerage.Text <> "18" Then
        InmProfile = InmProfile.Where(Function(post) (post.DATE_OF_BIRTH <= DateTime.Now.AddYears(0 - CInt(upperage.Text))))
    End If
    If ____.Text <> "" Then
        InmProfile = InmProfile.Where(Function(post) (post.MALE_OR_FEMALE = ____.Text))
    End If
    If Location.Text <> "" Then
        InmProfile = InmProfile.Where(Function(post) (post.STATE = Location.Text))
    End If

    ListView1.DataSource = InmProfile.ToList()
    ListView1.DataBind()

    I also want to be able to search for all records where the date is in a certain month or before or after a certain day, something like this:

    InmProfile = InmProfile.Where(Function(post) (post.DATE_OF_BIRTH.month = 3))

    This isn't working, but there must be a way to do this.  This is VB coder by the way.

    It took me over a week and a half to figure out how to get this to work, and I still don't fully understand what I'm doing.  If anyone knows a good tutorial or article that can explain this well, I woul appreciate a link.  But mu immediate need is how to filter on date parts.

    Diane
    Thursday, March 26, 2009 11:19 PM

Answers

  • Hi Diane,

    Can you explain the behavior you're seeing that makes you think it is not working? I have tried a similar query in both VB and C#, and it is translated to the correct SQL to do the date part filtering.
    Sunday, March 29, 2009 4:02 PM
    Answerer