如何解决Microsoft报表查看器中的数据源错误?

时间:2012-12-07 14:32:34

标签: c# sql windows rdlc

我在我的Windows项目中有报告页面。我包含 microsoftReportViewer 。在那个页面中,第一个组合框中的两个组合框是.items:

  1. FirmDetails
  2. ChittyHolding
  3. LoanDetails。
  4. 对应于在combobox1中选择这个项目,组合框中的项目将会改变。我需要报告根据2个梳子中的这个值。

    我的代码就像

    if (cbReprt.Text == "FirmDetails")
            {
    
                if (cbGeneral.Text == "AllFirmDetails")
                {
                    reportViewer1.RefreshReport();
                    SqlConnection con = new SqlConnection("Data Source=202.88.231.102;Initial Catalog=dbs_Merchant;Persist Security Info=True;User ID=sa;Password=abc123*");
                    con.Open();
                    allfirmdetails ds = new allfirmdetails();
                    string str = "Select * from View_2";
                    SqlCommand cmd = new SqlCommand(str, con);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(ds);
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                    reportViewer1.LocalReport.ReportPath = "F:\\MerchantAssociation\\MerchantAssociation\\Report7.rdlc";
                    reportViewer1.LocalReport.DataSources.Clear();
                    reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("allfirmdetails_View_2", dt));
                    reportViewer1.RefreshReport();
                }
    
    
                else
                {
                    reportViewer1.RefreshReport();
                    SqlConnection con = new SqlConnection("Data Source=202.88.231.102;Initial Catalog=dbs_Merchant;Persist Security Info=True;User ID=sa;Password=abc123*");
                    con.Open();
                    allfirmdetails ds1 = new allfirmdetails();
                    string str1 = "Select * from View_2 where FirmName='" + cbGeneral.Text + "'";
                    SqlCommand cmd1 = new SqlCommand(str1, con);
                    SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
                    da1.Fill(ds1);
                    DataTable dt1 = new DataTable();
                    da1.Fill(dt1);
                    reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                    reportViewer1.LocalReport.ReportPath = "F:\\MerchantAssociation\\MerchantAssociation\\firmwise.rdlc";
                    reportViewer1.LocalReport.DataSources.Clear();
                    reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("allfirmdetails_View_2", dt1));
                    reportViewer1.RefreshReport();
    
                }
            }
            else if (cbReprt.Text == "ChittyDetails")
            {
                if (cbGeneral.Text == "AllChittyDetails")
                {
                    reportViewer1.RefreshReport();
                    SqlConnection con = new SqlConnection("Data Source=202.88.231.102;Initial Catalog=dbs_Merchant;Persist Security Info=True;User ID=sa;Password=abc123*");
                    con.Open();
                    ChittyDetails ds2 = new ChittyDetails();
                    string str2 = "Select * from View_1";
                    SqlCommand cmd2 = new SqlCommand(str2, con);
                    SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
                    da2.Fill(ds2);
                    DataTable dt2 = new DataTable();
                    da2.Fill(dt2);
                    reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
                    reportViewer1.LocalReport.ReportPath = "F:\\MerchantAssociation\\MerchantAssociation\\allchitty.rdlc";
                    reportViewer1.LocalReport.DataSources.Clear();
                    reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("ChittyDetails_View_1", dt2));
                    reportViewer1.RefreshReport();
                }
    

    首先,我选择chittyholding详细信息。然后我收到了报告。然后我选择chitty details report,我得到了错误 **An error occured during local report processing .A data sourcr instance has not been supplied for the data source "ChittyHolding_View_7"**。如果我再次关闭并运行项目,则那个firmdetails选择将起作用。但是另一个将无效。这意味着只有一个选择我收到报告。为什么?请解决此错误

1 个答案:

答案 0 :(得分:0)

尝试在每个条件的开头调用reportViewer1.Reset();而不是reportViewer1.Refresh();