如何在VS2010使用水晶报表组件.docx_第1页
如何在VS2010使用水晶报表组件.docx_第2页
如何在VS2010使用水晶报表组件.docx_第3页
如何在VS2010使用水晶报表组件.docx_第4页
如何在VS2010使用水晶报表组件.docx_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

VS2010不在像VS2008及以前版本那样支持Crystal Report了,不过SAP公司还是很给劲的,随即发布了CR for2010的免费开放版。虽然如此,但刚上手使用的朋友们可能还是很费周折。下简述使用。如果只是为了能够在VS2010中运行有报表的程序,则可以简单的将运行程序所需的dll引入项目即可。如果你的机器没有这些组件可以来这下载:点我。一般只需要引用CrystalDecisions.CrystalReports.Engine.dll、CrystalDecisions.Shared.dll和CrystalDecisions.Web.dll即可。下载后将其放入web/bin下,然后引用它们就可以了。上述只适用于运行他人编写的有关报表的项目,做为开发者则还需进行其他工作。VS2010不在支持Crystal report的设计,我们下载SAP公司的免费版(for VS2010)来设计即可(设计过程同在VS2008中没什么区别,只是环境独立了)。随后将我们设计的第一个报表文件crTeacherWorkLoad.rpt文件拷贝到项目App_Data中。我们使用CryStalReportViewer控件来显示刚才设计好的rpt文件。VS2010IDE工具箱中不包含该控件,如果你安装了CR for VS2010则可以使用如下方法来显示该控件:如果没有此控件则可以直接将此控件的代码放入所需的aspx页面中,然后在这个aspx页面内注册此控件。控件代码如下所示:xhtml view plaincopyprint?1. 注册代码放到页面头头,代码如下所示:xhtml view plaincopyprint?1. 如此以来再有了前面的三个dll的引用,就可以使用此控件来显示所需要的报表内容了。显示过程代码如下所示:c-sharp view plaincopyprint?1. /加载报表文件,设置报表源 2. ReportDocument reportDocument = new ReportDocument(); 3. reportDocument.Load(Server.MapPath(././App_Data/crTeacherWorkLoad.rpt); 4. reportDocument.SetDataSource(DtAllTeacherWorkLoad);/);/DtAllTeacherWorkLoad是查询出来的DataTable,其字段同rpt文件字段相同 5.6.7. CrystalReportViewer1.ReportSource = reportDocument; 8. /将数据库信息传递给报表 9. /定义水晶报表的数据库连接信息 10. ConnectionInfo connectionInfo = new ConnectionInfo(); 11. string aservername, bDBName, cUserId, dPwd; 12. /获取服务器名、数据库名,登录名,密码 13. aservername = System.Configuration.ConfigurationManager.AppSettingsServerName; 14. bDBName = System.Configuration.ConfigurationManager.AppSettingsDataBase; 15. cUserId = System.Configuration.ConfigurationManager.AppSettingsUserId; 16. dPwd = System.Configuration.ConfigurationManager.AppSettingsPassWord; 17. connectionInfo.DatabaseName = bDBName; 18. connectionInfo.UserID = cUserId; 19. connectionInfo.Password = dPwd; 20. connectionInfo.ServerName = aservername; 21.22. /SetDbLoginForReport(connectionInfo); 23.24. TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo; 25.26. foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos) 27. 28.29. tableLogOnInfo.ConnectionInfo = connectionInfo; 30.31. csharp view plaincopyprint?1. /加载报表文件,设置报表源ReportDocumentreportDocument=newReportDocument();/加载报表文件,设置报表源 ReportDocument reportDocument = new ReportDocument();csharp view plaincopyprint?1. reportDocument.Load(Server.MapPath(././App_Data/crTeacherWorkLoad.rpt);reportDocument.Load(Server.MapPath(././App_Data/crTeacherWorkLoad.rpt);csharp view plaincopyprint?1. reportDocument.SetDataSource(DtAllTeacherWorkLoad);/); reportDocument.SetDataSource(DtAllTeacherWorkLoad);/);csharp view plaincopyprint?1. /DtAllTeacherWorkLoad是查询出来的DataTable,其字段同rpt文件字段相同CrystalReportViewer1.ReportSource=reportDocument;/DtAllTeacherWorkLoad是查询出来的DataTable,其字段同rpt文件字段相同 CrystalReportViewer1.ReportSource = reportDocument;csharp view plaincopyprint?1. /将数据库信息传递给报表/将数据库信息传递给报表csharp view plaincopyprint?1. /定义水晶报表的数据库连接信息ConnectionInfoconnectionInfo=newConnectionInfo();stringaservername,bDBName,cUserId,dPwd; /定义水晶报表的数据库连接信息 ConnectionInfo connectionInfo = new ConnectionInfo(); string aservername, bDBName, cUserId, dPwd;csharp view plaincopyprint?1. /获取服务器名、数据库名,登录名,密码aservername=System.Configuration.ConfigurationManager.AppSettingsServerName; /获取服务器名、数据库名,登录名,密码 aservername = System.Configuration.ConfigurationManager.AppSettingsServerName;csharp view plaincopyprint?1. bDBName=System.Configuration.ConfigurationManager.AppSettingsDataBase;bDBName = System.Configuration.ConfigurationManager.AppSettingsDataBase;csharp view plaincopyprint?1. cUserId=System.Configuration.ConfigurationManager.AppSettingsUserId; cUserId = System.Configuration.ConfigurationManager.AppSettingsUserId;csharp view plaincopyprint?1. dPwd=System.Configuration.ConfigurationManager.AppSettingsPassWord;dPwd = System.Configuration.ConfigurationManager.AppSettingsPassWord;csharp view plaincopyprint?1. connectionInfo.DatabaseName=bDBName;connectionInfo.UserID=cUserId;connectionInfo.DatabaseName = bDBName; connectionInfo.UserID = cUserId;csharp view plaincopyprint?1. connectionInfo.Password=dPwd;connectionInfo.ServerName=aservername;connectionInfo.Password = dPwd; connectionInfo.ServerName = aservername;csharp view plaincopyprint?1. /SetDbLoginForReport(connectionInfo); /SetDbLoginForReport(connectionInfo);csharp view plaincopyprint?1. TableLogOnInfostableLogOnInfos=CrystalReportViewer1.LogOnInfo;TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;csharp view plaincopyprint?1. foreach(TableLogOnInfotableLogOnInfointableLogOnInfos)foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)csharp view plainco

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论