Click here to Skip to main content
15,897,151 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,

I designed a report in VS 2010 using crystal reports. I have grouped the content based on project and a period (based on month and year) and I can see the result in the preview mode (design mode) as I wanted it to be.

But from the application when I pass a sql statement to filter down the results based on my selection of month and year, it populates all the records that are in the table.

To check if the statement was wrong, I placed a data grid view and checked but it works fine.

I used this kind of technique a while ago but this time it's not working as intended.

If this is not possible is there a way to prompt the user to input the month and year to see the desired records.

Thank you.

This was the procedure I used:

VB
Public Sub PerdiemReport()
        ReportPath = Application.StartupPath & "\Reports\CrystalReport1.rpt"

        conn = New OleDb.OleDbConnection(sconnString)

        Dim pdadt As DataTable = New DataTable()
        cmd.CommandText = "SELECT * FROM [per_diem_accomodation] WHERE [project number]='PR-01' AND " & _
                      "MONTH([current month])= 4 AND YEAR([current month])=2014"
        cmd.Connection = conn
        adp.SelectCommand = cmd
        'pdadt.Rows.Clear()
        adp.Fill(pdadt)
        'DataGridView1.DataSource = pdadt
        Dim title As String = "Project Payroll-Per diem Report"
        Preview(ReportPath, pdadt)

        'pdadt.Dispose()
        'pdadt = Nothing
        'adp.Dispose()
        'adp = Nothing
    End Sub

    Public Sub Preview(ByVal ReportPath As String, ByVal ds As DataTable)
        Dim rep As New ReportDocument
        Dim myTableLogonInfo As New TableLogOnInfo
        Dim myConnectionInfo As New ConnectionInfo
        'Dim myTables As Tables
        Dim myTable As Table
        rep.Load(ReportPath)
        rep.SetDataSource(ds)

        ' myTables = rep.Database.Tables
        With myConnectionInfo
            .ServerName = Application.StartupPath & "\projectpayrolls.accdb"
            .DatabaseName = ""
            .UserID = ""
            .Password = ""
        End With
        For Each myTable In rep.Database.Tables
            myTableLogonInfo = myTable.LogOnInfo
            myTableLogonInfo.ConnectionInfo = myConnectionInfo
            myTable.ApplyLogOnInfo(myTableLogonInfo)
        Next
        CrystalReportViewer1.ReportSource = rep
    End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900