水晶报告参数不正确

时间:2015-05-28 15:04:23

标签: c# asp.net

两个Crystal报告

  1. CrystalReport1.rpt
  2. employeemonthly.rpt
  3. 在信号aspx.net页面上调用这些报告。

     protected void Button1_Click1(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (rd.SelectedValue == "1")
                {
                    DateTime to = Convert.ToDateTime(sdate.Text);
                    dbconnect a = new dbconnect();
                    ReportDocument rDoc = new ReportDocument();
                        a.OpenConnection();
                        a.cmd = new SqlCommand("viewattandace_repoeting",a.con);
                        SqlDataAdapter da = new SqlDataAdapter();
                        DataSet ds = new DataSet();
                        a.cmd.CommandType = CommandType.StoredProcedure;
                        da.SelectCommand = a.cmd;
                        da.Fill(ds, "viewattandace_repoeting");
                        rDoc.Load(Server.MapPath("CrystalReport1.rpt"));
                        rDoc.SetDataSource(ds);
                        rDoc.SetParameterValue("date", to);
                        rDoc.SetParameterValue("depid", 1);
                        CrystalReportViewer1.ReportSource = rDoc;
                        CrystalReportViewer1.DataBind();
                        a.CloseConnection();
                        CleartextBoxes(this);
                }
                else
                    if (rd.SelectedValue == "2")
                    sd = Convert.ToDateTime(m.SelectedItem.Text + "/" + "1" + "/" + yt.SelectedItem.Text);
                        ed = LastDayOfMonth(sd);
                        dbconnect a = new dbconnect();
                        using (ReportDocument rDoc = new ReportDocument())
                        {
                            a.OpenConnection();
                      a.cmd = new SqlCommand("viewattandace_repoeting", a.con);
                            SqlDataAdapter da = new SqlDataAdapter();
                            DataSet ds = new DataSet();
                            a.cmd.CommandType = CommandType.StoredProcedure;
                            da.SelectCommand = a.cmd;
                            da.Fill(ds, "viewattandace_repoeting");
                            rDoc.Load(Server.MapPath("employeemonthly.rpt"));
                            rDoc.SetDataSource(ds);
                            rDoc.SetParameterValue("sdate", sd);
                            rDoc.SetParameterValue("edate", ed);
                            rDoc.SetParameterValue("depid", 1);
                            rDoc.SetParameterValue("email", eet.Text.Trim());
                            CrystalReportViewer1.ReportSource = rDoc;
                            CrystalReportViewer1.DataBind();
                            a.CloseConnection();
                        }                       
                    }
            }
        }
    

    一次只查看一个下拉列表选择索引的报告。 现在问题是只查看第一次选择的报告。当我选择其他报告时,显示此“参数不正确”。

    例如 我在下拉列表中选择了CrystalReport1报告并单击了按钮。然后报告视图,然后我选择了employeemonlyly报告并单击按钮然后显示“参数不正确”,反之亦然。

2 个答案:

答案 0 :(得分:0)

如果您有部分代码

,请更改
ReportDocument rDoc = new ReportDocument())

正如你在其他部分

那样

答案 1 :(得分:0)

我可以通过添加新的CrystalReportViewer控件来解决这个问题

     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {


        if (rd.SelectedValue == "1")
        {
            CrystalReportViewer2.Visible = false;

            yl.Visible = false;
            yt.Visible = false;



        }
        if (rd.SelectedValue == "2")
        {
            CrystalReportViewer1.Visible = false;


            sdate.Visible = false;
        }
    }

**按钮点击代码**

 protected void Button1_Click1(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {

            if (rd.SelectedValue == "1")

            {
                CrystalReportViewer1.Visible = true;
                    DateTime to = Convert.ToDateTime(sdate.Text);
                    dbconnect a = new dbconnect();
                    ReportDocument rDoc = new ReportDocument();
                    a.OpenConnection();
                    a.cmd = new SqlCommand("viewattandace_repoeting", a.con);
                    SqlDataAdapter da = new SqlDataAdapter();
                    DataSet ds = new DataSet();
                    a.cmd.CommandType = CommandType.StoredProcedure;
                    da.SelectCommand = a.cmd;
                    da.Fill(ds, "viewattandace_repoeting");
                    rDoc.Load(Server.MapPath("CrystalReport1.rpt"));
                    rDoc.SetDataSource(ds);
                    rDoc.SetParameterValue("date", to);
                    rDoc.SetParameterValue("depid", 1);
                    CrystalReportViewer1.ReportSource = rDoc;
                    CrystalReportViewer1.DataBind();
                    CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
                                  a.CloseConnection();




            }
            else
                if (rd.SelectedValue == "2")
                {
                    CrystalReportViewer2.Visible = true;
                    sd = Convert.ToDateTime(m.SelectedItem.Text + "/" + "1" + "/" + yt.SelectedItem.Text);
                    ed = LastDayOfMonth(sd);
                    dbconnect a = new dbconnect();

                    ReportDocument rDoc = new ReportDocument();

                        a.OpenConnection();
                        a.cmd = new SqlCommand("viewattandace_repoeting", a.con);
                        SqlDataAdapter da = new SqlDataAdapter();
                        DataSet ds = new DataSet();
                        a.cmd.CommandType = CommandType.StoredProcedure;
                        da.SelectCommand = a.cmd;
                        da.Fill(ds, "viewattandace_repoeting");
                        rDoc.Load(Server.MapPath("employeemonthly.rpt"));
                        rDoc.SetDataSource(ds);
                        rDoc.SetParameterValue("sdate", sd);
                        rDoc.SetParameterValue("edate", ed);
                        rDoc.SetParameterValue("depid", 1);
                        rDoc.SetParameterValue("email", eet.Text.Trim());
                        CrystalReportViewer2.ReportSource = rDoc;
                        CrystalReportViewer2.DataBind();
                        CrystalReportViewer2.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
                        a.CloseConnection();

} }