Click here to Skip to main content
15,895,964 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am working with rdlc report on a C# windows application, while retrieving a large set of data (say 10, 000 records) from Sqlite database, it takes more than three minutes for the report to generate and render, i think that is too much of time, i have tried to do a little optimization by indexing all fields in my where clause, yet no improvement, i cant do a stored procedure since Sqlite does not have support for it.

What I have tried:

C#
private DataSet GetData()
    {

        string select = "SELECT DISTINCT OrganisationId AS OrgId,OrganisationName AS OrgName,TaxIdNumber AS TIN,StaffId,StaffName,Department AS Dept,Position,Month,Year,SUM(NoOfMonthsWorked) AS NMnth," +
                        "SUM(BasicSalary) AS BasicSalary,SUM(TransAllowance) AS Transp,SUM(UtilityAllowance) AS Utility,SUM(HousingAllowance) AS Housing,SUM(LeaveAllowance) AS Leave,SUM(ThirteenthMonthAllowance) AS ThirteenMnth," +
                        "SUM(OvertimeAllowance) AS Overtime,SUM(EntertainmentAllowance) AS EnterMnt,SUM(DomesticAllowance) As Domestic,SUM(EducationAllowance) AS Education,SUM(PersonalAllowance) AS Personal,SUM(OtherAllowances) AS Others," +
                        "SUM(HealthFund) AS NHIS,SUM(HousingFund) AS NHF,SUM(LifeAssurance) AS LA,SUM(Gratuities) AS Gratuities,SUM(Pension) AS Pension,SUM(OtherStatutoryDeductions) AS OtherDeducts," +
                        "SUM(ConsolidatedRelief) AS CRA,SUM(TotalRelief) AS TotalRelief,SUM(TaxableIncome) AS TaxableIncome,SUM(TaxExempts) As TTaxExempt,SUM(GrossIncome) AS GrossIncome,SUM(MonthlyTaxDue) AS TaxPayable " +
                        "FROM IncomeTax WHERE(OrganisationId = @OrganisationId AND Year = @Year) GROUP BY StaffId";
        using (SQLiteConnection con = new SQLiteConnection(connstring))
        {
            using (SQLiteCommand cmd = new SQLiteCommand(select))
            {
                using (SQLiteDataAdapter sda = new SQLiteDataAdapter())
                {
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandTimeout = 9000000;
                    cmd.Parameters.Add("@OrganisationId", DbType.String, 50).Value = txtOrgId.Text.ToUpper();
                    //cmd.Parameters.Add("@Month", DbType.String, 50).Value = cboMonthSearch.SelectedItem.ToString();
                    cmd.Parameters.Add("@Year", DbType.String, 50).Value = cboYearSearch.SelectedItem.ToString().ToUpper();
                    using (DataSet dsCustomers = new DataSet1())
                    {
                        sda.Fill(dsCustomers, "DataTable2");
                        if (dsCustomers.Tables[1].Rows.Count == 0)
                        {
                            reportViewer1.Visible = false;
                            MessageBox.Show("Records not found!");
                        }
                        else
                        {
                            reportViewer1.Visible = true;
                        }
                        return dsCustomers;
                    }
                }
            }
        }
    }


The button Click Event:
C#
private void btnShowReport_Click(object sender, EventArgs e)
    {
        errorProvider1.Clear();
        if (txtOrgId.Text != "")
        {
            if (cboYearSearch.SelectedIndex != 0)
            {
                DataSet dsCustomers = GetData();
                ReportDataSource datasource = new ReportDataSource("DataSet1", dsCustomers.Tables[1]);
                this.reportViewer1.LocalReport.DataSources.Clear();
                reportViewer1.ProcessingMode = ProcessingMode.Local;
                // the ReportPath is relative to the page displaying the ReportViewer
                reportViewer1.LocalReport.ReportPath = "Report2.rdlc";
                this.reportViewer1.LocalReport.DataSources.Add(datasource);
                this.reportViewer1.RefreshReport();
            }
            else
            {
                errorProvider1.SetError(cboYearSearch, "Select Year!");
                cboYearSearch.Focus();
            }
        }
        else
        {
            errorProvider1.SetError(txtOrgId, "Enter OrgId!");
            txtOrgId.Focus();
        }
    }


I will appreciate if anyone could assist on how to get it display a bit more faster. Thanks
Posted
Updated 3-May-17 4:30am
v2
Comments
CHill60 3-May-17 11:01am    
I don't understand how you are getting any results at all as you have items in the SELECT that are not aggregate functions nor are they in the GROUP BY clause
Uwakpeter 3-May-17 11:16am    
Query finished in 0.046 second(s) while running on sqlite query window. i have another select statement that does not use group by clause, it still take the same amount of time to display!
CHill60 3-May-17 12:38pm    
Ok, I've never used SQLite before but now I know it doesn't adhere to T-SQL standards for Grouping.
However if the query runs in 0.046 seconds then the problem must be with your report. Do you have any calculations or fancy formatting in your report?
Uwakpeter 3-May-17 13:46pm    
The report has 35 columns, i used this: =IIF((Fields!Dept.Value ="Nill"), true,false) for column visibility and also:
=FormatNumber(Fields!Transp.Value,2) on 20 Textbox expressions, could this be the issue?
Richard Deeming 4-May-17 9:07am    
Since you're returning dsCustomers from your GetData method, you don't want to put it in a using block.

Replace:
using (DataSet dsCustomers = new DataSet1())

with:
DataSet dsCustomers = new DataSet1();


Your query only returns a single table, so it's not clear why you're always accessing the second table? (Remember, the collections use zero-based indexing, so Tables[1] returns the second table.)

Is there anything odd going on in your custom DataSet1 class? Have you tried using a raw DataSet instead?

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