How to filter age in rdlc reportviewer base on date of birth with vb.net
I want to filter age range based on two (2) textboxes value. I have two (2) textboxes in a form, the first textbox is for beginning of range and second is for ending of range (example: 45(first textbox) to 60(second textbox)).A report is containing student's fullname, date of birth, and age column. The age column is not from the database but from the expression: round(DateDiff("m",fields!DOB.Value,Now() )/12)
I tried the code below but it did not work:
Code:
Dim connstring As String
connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=studentrecords.accdb"
Dim conn As OleDbConnection = New OleDbConnection(connstring)
Dim displaystr As String = "SELECT studentfullname, dateofbirth, Round(DateDiff('m',studenprofile_records.Date_of_Birth,Date())/12,2) AS Age FROM studentprofile_records WHERE Age BETWEEN'" & CInt(txtagefrom.Text) & "' AND Age <='" & CInt(txtageto.Text) & "'"
Dim cmddisplay As New OleDbCommand(displaystr, conn)
conn.Open()
cmddisplay.ExecuteNonQuery()
conn.Close()
Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.ZoomMode.PageWidth)
Me.ReportViewer1.RefreshReport()
Re: How to filter age in rdlc reportviewer base on date of birth with vb.net
I tried this is Access with DateDiff and Year
don't know why you are using m (Month)
note this is executed in Access, you have to adapt to your above code
Code:
SELECT Employees.FirstName, Employees.LastName, Employees.BirthDate, DateDiff("yyyy",[Birthdate],Now()) AS [Age is]
FROM Employees
WHERE (((DateDiff("yyyy",[Birthdate],Now())) Between 60 And 66))
ORDER BY DateSerial(Year(Now()),Month([BirthDate]),Day([BirthDate]));