欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

.NET 水晶报表使用代码

程序员文章站 2024-03-09 15:15:53
需要的命名空间 using crystaldecisions.crystalreports.engine; using crystaldecisions.web; usin...
需要的命名空间
using crystaldecisions.crystalreports.engine;
using crystaldecisions.web;
using crystaldecisions.shared;
----------------------------------------------------
建一个数据集文件
*.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 = "";