Results 1 to 2 of 2

Thread: How to filter age in rdlc reportviewer base on date of birth with vb.net

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2019
    Posts
    54

    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()

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,129

    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]));
    Last edited by ChrisE; Feb 15th, 2021 at 02:22 AM.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width