0

我在我的 Windows 项目中有报告页面。其中包括microsoftReportViewer。在该页面中,有两个组合框。第一个组合框中的项目是:

  1. 公司详情
  2. 奇蒂控股
  3. 贷款详情。

对应选择combobox1中的这个项目,combobox中的项目会改变。我需要根据2个combbox中的这个值报告。

我的代码就像

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"**。如果我关闭并再次运行该项目,那么该坚定详细信息选择将起作用。但另一个将不起作用。这意味着只有一个选择我才能获得报告。为什么?请解决这个错误

4

1 回答 1

0

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

于 2012-12-07T15:29:05.140 回答