按会话显示水晶报表 [英] Displaying crystal reports by a session
问题描述
您好,先生和女士.美好的一天..我有这个asp.net网站,它生成Staff的记录.输入工作人员的ID号时在texbox中,然后单击"Generate record"按钮,该页面将被重定向到必须查看报告的另一页面.
在我的第一个aspx.cs(session.aspx)中:
Hi sir and ma''am. good day.. I have this asp.net website that generate records of Staff. As you type staff''s Id no. in a texbox and click the ''Generate record'' button, the page will be redirect to the another page of which the report has to be viewed.
In my first aspx.cs (session.aspx):
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class session : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["compNo"] = TextBox1.Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("Default.aspx");
}
}
在第二页中.aspx(Default.aspx):
and in my second page.aspx (Default.aspx):
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrystalDecisions.Shared;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["compNo"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
ConnectionInfo con = new ConnectionInfo();
con.ServerName = "myservername";
con.DatabaseName = "My_database";
CrystalReportViewer1.ParameterFieldInfo.Clear();
CrystalReportViewer1.ReportSource = Server.MapPath("report.rpt");
ParameterFields parameter = CrystalReportViewer1.ParameterFieldInfo;
ParameterField staffno = new ParameterField();
staffno.Name = "par_staffno";
ParameterDiscreteValue par_staffno_value = new ParameterDiscreteValue();
par_staffno_value.Value = Label1.Text;
staffno.CurrentValues.Add(par_staffno_value);
parameter.Add(staffno);
foreach (TableLogOnInfo tlf in CrystalReportViewer1.LogOnInfo)
{
tlf.ConnectionInfo = con;
}
}
}
我有我的report.rpt,我已经在其中填充了指定的字段,例如:
Staff_No,First_Name,Middle_Name,Last_Name
另外,我已经从第二页的工具箱中拖动了CrystalReport Viewer.
这就是我所做的一切.我忘记做的任何事情,我还不知道.
我没有错.但是,当我在浏览器中运行该报告时,该报告未显示在浏览器中,并且在浏览器末尾显示了参数不正确"文本.
-我将SQL Server用于数据库,将Visual Studio 2008(C#)用于代码和所有内容..
先生和女士,我做错了什么? :)
I have my report.rpt which I have already populated with designated fields like:
Staff_No, First_Name, Middle_Name, Last_Name
Also, I have already drag the CrystalReport Viewer from toolbox in my second page.
That''s all what I have done. Any thing that I forgot to do, I do not know yet.
I got no errors. But when I run it in the browser, the report does not displayed in the browser and I got this "The parameter is incorrect" text at the end of my browser.
-- I''m using SQL server for my database, Visual Studio 2008 (C#) for the codes and everything..
What I have done wrong sir and ma''am? :)
推荐答案
你好ninj23,
ReportDocument包含方法 ReportDocument.SetParameterValue [
Hello ninj23,
The ReportDocument contains a method ReportDocument.SetParameterValue[^] which you can use to set your parameters. Something like this;
// Assuming you have a CrystalReportViewer named CRViewer
protected void Button1_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
ConnectionInfo con = new ConnectionInfo();
con.ServerName = "myservername";
con.DatabaseName = "My_database";
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("report.rpt"));
// rpt.SetParameter([0 based index of parameter], [value]);
rpt.SetParameter(0, Session["compNo"].ToString());
CRViewer.ReportSource = rpt
foreach (TableLogOnInfo tlf in CrystalReportViewer1.LogOnInfo)
{
tlf.ConnectionInfo = con;
}
}
请记住,此代码是直接写到浏览器中的,所以如果不编译,不要感到震惊.
一点点的额外阅读给您;
- ReportDocument类 [ ReportDocument.SetDatabaseLogon [
Please keep in mind that this code was written directly into the browser so dont be shocked if it doesnt compile.
Little bit of extra reading for you;
- ReportDocument Class[^]
- ReportDocument.SetDatabaseLogon [^]
这篇关于按会话显示水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!