欢迎来到Introzo百科
Introzo百科
当前位置:网站首页 > 技术 > VS2010开发报表_Crystal Reports in Visual Studio 2010(VS2010中的水晶报表)

VS2010开发报表_Crystal Reports in Visual Studio 2010(VS2010中的水晶报表)

日期:2023-09-23 21:50

VS2010?创建和使用自定义数据源报表详细过程

首先看一下最终效果(显示数据进行了加密,所以成了乱码)

图1.窗体的效果

图2.点击预览时的效果

1.创建显示报表的窗体

新建窗体命名为ReportForm并修改窗体名为学生成绩

在窗体上只需要拖放一个ReportViewer 控件

2.新建数据集为DSofStudent.xsd

在数据集中插入要显示在报表中的表结构(本例为此,注意: 字段名必须和要传向报表的数据表DataTable吻合)

3.插入报表并命名为StudentReport

新建完成后在报表页面右击插入表,在此选中刚创建的数据集中的表,如下图

然后设置表头\表头的背景色\绑定显示字段,如下图

这里说一下如何设置每行显示的颜色

此处选择设置背景为表达式: ?=iif(Fields!Grade.Value = 0,"Red", "GreenYellow") ?意思是如果Grade为0则显示红色,否则为黄绿色。

4. 传入数据

在窗体中的ReportViewer控件中选择报表源,如下

接下来在初始化该窗体时,传入要显示的表的内容

?DataSet ds = new DataSet(); ? ? ? ? ? ? ds = stu.GetStudentList2(sschoolname, sclassname)(传入自己要显示的数据集即可);? ? ? ? ? ? ? this.reportViewer1.LocalReport.DataSources.Clear(); ? ? ? ? ? ? this.reportViewer1.LocalReport.DataSources.Add(new www.introzo.comDataSource("StuGrade", ds.Tables[0])); ? ? ? ? ? ? this.reportViewer1.RefreshReport();??

综上,VS2010的报表自定义数据源的创建和使用写完了。

如有不完善的地方,请各位提提建议,本人进行完善。

?

? 页眉、页脚增加好了后,我们还要为报表做一个数据源,

在解决方案资源管理器中,右击工程"ReportViewerTest"->添加->新建项,

点击“新建项”后,在出来的“添加新项”对话框的模板中选“数据集"

名称就用默认的DataSet1.xsd 。

?

?

点击“添加”按钮后,出现DataSet1.xsd设计画面。

打开工具箱,将TableAdapter拖到DataSet1.xsd设计画面。

?

将TableAdapter拖到DataSet1.xsd设计画面后会出现数据源配置向导,

再点击"新建连接":

?

?

在出来的“添加连接”对话框中,服务器名中输入"(local)"(因为在本地安装了

Sql Server 2008),在“选择或输入一个数据库名”中下拉按钮后,显示了本地所

有数据库,我们选择"WP7CityLife"库(WP7CityLife是我毕业设计用到的一个数据库,你们的话随便选个在的数据库都没关系):

选择好数据库后一直下一步下一步

点下一步后出现下面画面,这里我们就选“使用 SQL 语句”,再点下一步:

?

?

出现上面的画面后,在其中填入SQL语句,大家如果嫌麻烦的话 也可以直接使用 查询生成器来快速的获取要查询的数据

填入Sql语句后,点下一步,出现下面的画面:

?

它已经勾选了"填充 DataTable",方法名: "Fill" 和勾选了"返回 DataTalbe",

方法名称: "GetData"; 就用它的这些默认的,点下一步,显示了“向导结果”,如下面的画面:

?

在上面画面中点击完成,显示了下面的画面:

?

至此报表的“数据源”就做好了。

PS:接下来就是一些本人的个人数据源的使用经验以供大家参考,如果有更好的方法希望大家可以提出来 一起探讨,毕竟我还是初学者所以肯定会有很多不对的地方

在上面 我们是直接使用TableAdapter 来创建数据源的,大家也可以选择用datatable来创建数据源,我就是使用datatable来创建数据源的,

个人使用经验是这样的

将要使用的数据全都创建大datatable的列中 ,例如你要a表的a1 a2和b表中的 b1 b2??,4个字段,你只要将datatable 拉出来 将a1 a2 b1 b2 四个列创建出来先就可以了如下图:

之后的话 我们只要将获取的数据对应的名称与datatable一样就好了

简单来讲 如下代码

DataTable dt =new DataTable()

dt.Columns.Add("a1", typeof(string));dt.Columns.Add("a2", typeof(string));dt.Columns.Add("b1", typeof(string));dt.Columns.Add("b2", typeof(string));

....//此处获取数据

....//此处获取数据

....//此处获取数据

?

?

等到界面绑定数据的时候将数据源为a1,a2,b1,b2的那个datatable的数据绑定成该dt就OK了。

如果还不明白,就等以后再了解。。

?这章就讲这么多了。今天就到这里了 以后有空再写。。。

转载于:https://www.introzo.com/PleaseInputEnglish/archive/2012/09/17/2689312.html

?? 我们乐意告诉各位水晶报表在支持VS2010的方式上将发生一些变化.?? 自从VB2 1993年发布以来,水晶报表一直是微软开发人员的一个重要体验.我们全力支持微软开发人员,并将继续为微软技术提供世界级报表解决方案.?? 我们一直与微软合作,以确保为VS客户提供尽可能平滑的变更过渡.

?? 什么正在改变??? 1.水晶报表将不再是VS2010的一部分.?? 2.取而代之的是,VS2010的水晶报表将由SAP以免费下载,无需注册的方式提供.?? 3.因为水晶报表将独立交付,所以交付日期还没确定.我们承诺在VS2010正式发布时会出一个beta版本.?? 4.正式版本将最迟不晚于2010年第三季度发布.?? 5.VS2010的水晶报表最终用户许可协议将与VS2008一致,与VS2008中的最终用户许可协议相比,唯一的实质性变化是不再包含免费的WEB应用程序水晶报表外部可再分发包,它必须与Crystal Reports Developer Advantage运行时许可证一起单独购买.?? 6.MSM(Merge Module)运行时不再可用.MSI(Windows Installer)与ClickOne将是运行时引擎支持的部署方法.

?? 什么是不变的? ?? 1.与VS2008一样,内嵌了VS2010水晶报表运行时的胖客户服务器应用程序的不受限内部分发包仍然存在.?? 2.与VS2008一样,内嵌了VS2010水晶报表运行时的胖客户应用程序的不受限外部分发包仍然存在.?? 3.同时支持32位与64位运行时.与VS2008水晶报表Basic相比,这是相同的,但是,对于水晶报表2008的客户来说,64位运行时是一个重大的实质性的新特征.

?? ?? 新特征有哪些??? 1.新的WPF查看器.?? 2.新的XLSX导出,利用了用于只有数据的Excel导出的大方格.?? 3.新的称为RPTR的只读RPT文件,它允许你控制谁可以看见报表设计的内部.通过从一个RPT文件导出,你可以创建一个RPTR文件.之后,RPTR文件只能由报表查看者打开.为了保护你的内部商业逻辑,我们的报表设计器工具将拒绝打开RPTR文件.?? 4.增强的内嵌报表设计器,如你现在能创建动态的级联参数.?? 5.为方便基于COM的RDC客户,增强了各种.NET API,以提高可移植性.?? 6.更轻的重量级英语运行时,以减少部署量.?? 7.更灵活的MSI部署,以替代MSM用例.

?? 总之,VS2010开发人员将:?? 1.与以往不同的方式接受水晶报表.?? 2.继续从与VS完全整合在一起的免费水晶报表中受益.?? 3.与VS2008相比,在功能上获得重大升级.?? 4.看见对许可证的少许修改,这会对从外部再分发web应用程序的用户有很大影响.

?? 在第一季度,对于Beta版的发布时间及功能,我们将有更详细的说明.?? 说明:???????? RC就是Release Candidate(候选版本)的简称 ???????? GA:General Availability,正式发布的版本,在国外都是用GA来说明release版本的??? From http://www.introzo.com/irj/scn/weblogs?blog=/pub/wlg/14514Company: SAPPosted on Dec. 10, 2009 11:58 AM in

Crystal Reports

, Interoperability .NET

URL:?http://www.introzo.com/Forums/en/vscrystalreports/thread/24bd3f52-8b22-47ee-90eb-2504d49a4625?prof=required

We're happy to share some changes in how Crystal Reports will support Microsoft Visual Studio 2010.

Ever since Visual Basic 2 released in 1993, Crystal Reports has been an integral part of the Microsoft developer experience.?? We are fully committed to Microsoft developers, and will continue to provide world class reporting solutions for Microsoft technologies.

We are working with Microsoft to ensure this transition is as smooth as possible for Visual Studio customers.

What is changing?

Crystal Reports will no longer be included in Visual Studio 2010 Instead, Crystal Reports for Visual Studio 2010 will be provided by SAP as a free download, no registration required. Because its now delivered separately, the delivery dates don't exactly line up.? We are committed to have a beta version at the time that Visual Studio 2010 goes GA. A production release will be no later than Q3 2010. The EULA for Crystal Reports for Visual Studio 2010 will match the Crystal Reports 2008 EULA.? The only material change when comparing the EULA with Visual Studio 2008 is that free external redistribution for web applications is no longer included.? Its purchased separately with the Crystal Reports Developer Advantage runtime license. The MSM runtime will be unavailable.? MSI and ClickOnce will be the supported deployment methods for the runtime engine.

What is not changing?

Unlimited internal distribution of thick client and server applications that embed the Crystal Reports for Visual Studio 2010 runtime is included - same as Visual Studio 2008. Unlimited external distribution of thick client applications that embed the Crystal Reports for Visual Studio 2010 runtime is included - same as Visual Studio 2008. Both 32-bit and 64-bit runtimes are available.? This is unchanged compared to Crystal Reports Basic for Visual Studio 2008, but the presence of a 64-bit runtime is a major net new feature for Crystal Reports 2008 customers.

What are the new features?

New WPF Viewer New XLSX export to take advantage of the big grid for data-only Excel exports Improved report viewing experience provides more interactivity to end users of your reports. New read-only RPT file called RPTR that allows you to control who can see the internals of your report design.? You create a RPTR file by exporting it from an RPT.? After that, RPTR files can only be opened by the report viewers.? oUR Report designer tools will refuse to open RPTR files - protecting your internal business logic in the report. Improved embedded report designer - for example you can now create dynamic, cascading parameters. Various .NET API improvements to improve the migration for COM-based RDC customers. Lighter weight English-only runtime for reduced deployment size. More flexible MSI deployment to replace MSM use cases.

To conclude, Visual Studio 2010 developers will:

Receive Crystal Reports in a different manner than before. Continue to benefit from a free version of Crystal Reports that's fully integrated with Visual Studio. Get a significant upgrade in features compared to Visual Studio 2008. See slight modifications to licensing that will mostly impact those who redistribute web applications externally.

In Q1 we'll have more?details about the features and timing of the beta release.

关灯