惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy International News Feed
I
Intezer
T
Tenable Blog
S
Schneier on Security
Project Zero
Project Zero
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Know Your Adversary
Know Your Adversary
博客园 - 司徒正美
The Cloudflare Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News and Events Feed by Topic
博客园 - 叶小钗
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题
aimingoo的专栏
aimingoo的专栏
S
Secure Thoughts
Forbes - Security
Forbes - Security
T
The Exploit Database - CXSecurity.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
罗磊的独立博客
IT之家
IT之家
H
Hacker News: Front Page
I
InfoQ
云风的 BLOG
云风的 BLOG
S
Security Affairs
M
MIT News - Artificial intelligence
GbyAI
GbyAI
Jina AI
Jina AI
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
Webroot Blog
Webroot Blog
L
Lohrmann on Cybersecurity
A
About on SuperTechFans
Attack and Defense Labs
Attack and Defense Labs
The Register - Security
The Register - Security
V
V2EX
G
Google Developers Blog
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
J
Java Code Geeks
W
WeLiveSecurity
Cloudbric
Cloudbric
T
Tor Project blog

博客园 - 木人(我现在不是老大)

ERP系统的专业化发展趋势 讨厌的real和float数据 Svcutil使用点滴 windows server2003企业版64位安装sql server2008企业版64位 读书笔记 UltraGrid(16) 水晶报表使用push模式(2) SQL SERVER2000存储过程调试 读书笔记 UltraGrid(15) 读书笔记 UltraGrid(14) 读书笔记 UltraGrid(12) 读书笔记 UltraGrid(11) 读书笔记 UltraGrid(10) 读书笔记 UltraGrid(9) 读书笔记 UltraGrid(8) 读书笔记 UltraGrid(7) 读书笔记 UltraGrid(6) 读书笔记 UltraGrid(5) 读书笔记 UltraGrid(4) 读书笔记 UltraGrid(3)
水晶报表使用push模式(1)
木人(我现在不是老大) · 2012-02-23 · via 博客园 - 木人(我现在不是老大)

1:数据建模。
在设计报表前,我们首先要根据展示的内容和查询的条件确定数据模型,比如我们要统计任意时间段每个班组的产量,那我们的模型可能设计如下:
WorkDate   Date
WorkTeam   char
WorkPcs    int
WorkSqr    float
这个实体的定义取决于报表要展示的内容以及过滤的条件。
比如要方便按月份来查询,可以增加:WorkMonth  char
至于其内容来源,有可能是直接取自表中、视图或查询语句,也可能来源于一个存储过程。
在设计的时候不用考虑其如何得来的。
2:建立XSD
1)通过vs.net建立数据集来,然后人工建立DataTable,从而生成XSD文件。
xsd文件名不重要,重要的是DataTable的名字,这个就是填充DataSet中DataTable的名字。
其生成的强类型的类文件对设计报表是没有用处的。
数据类型是一定要定义的,以方便在水晶报表设计中能对该列进行处理;
主键等约束,包括字符长度等,个人觉得没必要。除非该xsd文件要用于验证数据的有效性。
2)通过vs.net建立数据集,然后从服务器资源管理中拖拽表或视图来生成XSD;
这时工具会自动根据表或视图的定义来生成XSD及对应的类。
包括数据类型、长度以及主键等。
我们查看其代码文件,可以发现对应的类代码有点“异常复杂”,这就是所谓的强类型的dataset生成。
缺省是生成了TableAdapter的。这个实际上可以删除,以减少XSD文件的大小,大约变为原来的1/5。
查看XSD文件,可以发现对表的操作,如查询、插入、更新和删除等操作语句都体现在XSD中的。
3)通过vs.net建立数据集,增加一个查询,通过改查询来生成XSD.
4) 自己生成XSD,如:
string sql = "select * from " + tableName;
DataSet data = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, this._connectString);
data.Tables.Add(tableName);
da.FillSchema(data,SchemaType.Source,tableName);
data.WriteXml(fileName, XmlWriteMode.WriteSchema);
3:设计报表文件。
如使用Crystal Reports2008或者Crystal Reports for .NET4.0来设计.
在创建新连接中,选择Ado.net,然后选择对应的xsd文件,确定即可。
其余设计过程和直接连接数据库设计没有什么区别。
4.显示报表
ReportDocument rd = new ReportDocument();
rd.Load("Throughput.rpt");
DataSet data = new DataSet();
SqlConnection cnn = new SqlConnection(connectString);
SqlDataAdapter da = new SqlDataAdapter(selectSQL, cnn);
da.Fill(data, "Throughput");
rd.SetDataSource(data);
this.crystalReportViewer1.ReportSource = rd;
注意:fill中的表名必须和设计文件中的表名相同!

da.Fill(data);
rd.SetDataSource(data);
则不能正确展示报表的。

当然也可以使用这种方式!
da.Fill(data);
rd.SetDataSource(data.Tables[0]);