水晶报表参数不正确
本文关键字:不正确 参数 报表 水晶 | 更新日期: 2023-09-27 17:51:08
两个水晶报告
- CrystalReport1.rpt
- employeemonthly.rpt
在信号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报告并单击按钮。然后是报告视图,然后我选择员工月度报告并单击按钮,然后显示此"参数不正确",反之亦然。
我可以通过添加新的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();
}}
请将您的部分代码更改为
ReportDocument rDoc = new ReportDocument())