|
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
----------------------------------------------------
建一個數(shù)據(jù)集文件
*.xsd
-----------------------------------------------------
在頁面中加一個報表查看控件
CrystalReportViewer
--------------------------------------------------------
后臺代碼
dsJob dsjob = new dsJob();
SqlConnection scn = new SqlConnection("server=.;uid=sa;pwd=111111;database=pubs;");
scn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", scn);
DataSet ds = new DataSet();
sda.Fill(ds);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
DataRow drjob = dsjob.Tables[0].NewRow();
drjob["job_id"] = dr["job_id"];
drjob["job_desc"] = dr["job_desc"];
dsjob.Tables[0].Rows.Add(drjob);
}
}
CrystalReportSource crysource = new CrystalReportSource();
crysource.ReportDocument.Load(Server.MapPath("CryPort.rpt"));
crysource.ReportDocument.SetDataSource(dsjob);
crysource.DataBind();
cryview.ReportSource = crysource;
cryview.DataBind();
//給報表上的 text 控件賦值
TextObject txtname = (TextObject)crysource.ReportDocument.ReportDefinition.ReportObjects["控件Name"];
txtname.Text = "";
AspNet技術(shù):.NET 水晶報表使用代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。