我正在使用rdlc报告C#windows应用程序,同时从Sqlite数据库检索大量数据(比如10,000条记录),报告生成和渲染需要3分钟以上,我认为是太多的时间,我试图通过索引我的where子句中的所有字段做一点优化,但没有改进,我不能做一个存储过程,因为Sqlite不支持它。以下是我的代码:
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;
}
}
}
}
}
Click事件:
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();
}
}
如果有人能协助如何让它显示得更快,我将不胜感激。感谢