How to get datepart in dynamic query
Posted: Fri 27 Mar 2009 01:41
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 "" Then
InmProfile = InmProfile.Where(Function(post) (post.MALE_OR_FEMALE = txtGender.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
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 "" Then
InmProfile = InmProfile.Where(Function(post) (post.MALE_OR_FEMALE = txtGender.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