报表查看器不显示嵌入式.RDLC报表中的选定字段 [英] Report Viewer Not Displaying Selected Fields in an Embedded .RDLC Report

查看:112
本文介绍了报表查看器不显示嵌入式.RDLC报表中的选定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:



虽然我很擅长在WinForm应用程序中使用嵌入式报表(.rdlc)(在C#中),但我想我理解基本概念。我一直在尝试和练习,以便在这方面做得更好。然而,我有一个奇怪的问题。今天早上我谷歌搜索了一个解决方案或领导但是有用,所以我问社区。让我来描述一下这个问题。请注意,这只是简单的练习练习而不是真正的应用程序。



这是我似乎能够毫无问题地做的事情。我可以将一个非常基本的报告(.rdlc)嵌入到我的WinForm中,并通过Report Viewer控件显示报告。当然,所有字段都在输出数据。这告诉我至少我已将所有数据布线到位,可以这么说。这意味着我的DataSet(.xsd)似乎是正确的,BindingSource,TableAdapters和Report DataSet也是如此。这里有很多作品,但我慢慢了解它。



但是对于我未来的应用程序,我想使用SQL Server Compact Edition 4.0数据库。所以我针对Northwind40数据源创建了所有适当的连接和对象,一切都很好。我觉得这个小小的CE 4.0数据库已经安装在某个地方并且很适合练习。



所以我使用相同的技能并且主要创建一个简单的报告显示来自[Northwind40]。[Categories]表中的CategoryID和Category,Description字段在我的表控件中的报表上。当我运行表单并且ReportViewer Control完成它的工作时,奇怪的是,我看到的只是带有Description的列。 CategoryID和Category列都是空白的。当我再次导出到Excel时,CategoryID和Category是空白的,并且描述很好并填写每一行。 CategoryID是System.int,Category和Description都是System.String。



嗯,我不确定这是一个问题,因为我使用的是SQL CE 4.0数据库?我不认为它是我的数据集,BindingSource或那些数据组件,因为我正在获取我想要的数据。它只是不会显示三个字段中的两个。我尝试了各种改变字体颜色,列大小,右/左单元格对齐等但没有。



我的Form1_Load代码中有两行:



Hello:

Although I am very new to using embedded Reports (.rdlc) in WinForm applications (in C#), I think I understand the basic concepts. I've been experimenting and practicing to get better at this. Yet, I am having one strange problem. I've Google searched all this morning for a solution or a lead but to avail so I am asking the community. Let me describe the issue. Please note, this is just simple practice exercise stuff and not a real application at this point.

Here is what I seem to be able to do without an issue. I can embed a very basic report (.rdlc) into my WinForm and show the report via the Report Viewer control. And, of course, all the fields are outputting their data. This tells me at least I have all the data wiring in place, so to speak. This means my DataSet (.xsd) seems correct and the BindingSource, TableAdapters, and the Report DataSet as well. There are lot of pieces here but I am slowly understanding it.

But for my future application I want to use a SQL Server Compact Edition 4.0 database. So I create all the appropriate connections and objects against the Northwind40 datasource and all is fine. This little CE 4.0 database I think got installed somewhere along the way and its good to practice with.

So I use the same skills and mostly create a simple report that shows the CategoryID and Category, Description fields from the [Northwind40].[Categories] table in my table control on the report. When I run the form and ReportViewer Control does its thing, strangely, all I see is the column with Description. Both CategoryID and Category columns are blank. When I export to Excel, again, CategoryID and Category are blank and Description is nice and filled in for each row. CategoryID is System.int and both Category and Description are System.String.

Well, I'm not sure if this an issue because I'm using SQL CE 4.0 database? I don't think its my dataset, BindingSource, or those data components because I am getting back the data I want. It just simply won't display two out of the three fields. I tried all sorts of changing the font color, column sizes, right/left cell alignment etc but nothing.

There are two lines in my Form1_Load code:

this.CategoriesTableAdapter.Fill(this.Northwind40.Categories);
this.reportViewer1.RefreshReport();





And我在.RefreshReport行上放了一个断点。此时,Northwind.Categories DataTable当然具有CategoryID(1)和Category(Beverages)的值,​​但它们再次不会在报告中显示描述(软饮料,咖啡,茶,啤酒和啤酒)



天哪,我只是不确定还能尝试什么。



欢迎任何帮助或潜在客户。先感谢您。再一次,这只是练习/学习问题,所以请给那些真正的生产问题优先于我的学习问题的人。再次感谢。



And I have put a breakpoint on the .RefreshReport line. At that point, certainly the Northwind.Categories DataTable has values for CategoryID (1) and Category (Beverages) but again they won't show on the report only the Description (Soft drinks, coffees, teas, beer, and ale)

Gosh, I'm just not sure what else to try.

Any help or leads will be welcome. Thank you in advance. And again, this is just practicing/learning question so please do give others who have real Production issue priority over my learning question. Thanks again.

推荐答案

快速解决方案:表格中的字段名称中不得包含空格。



你好每个人



我想我可能知道这里发生了什么。实际上,也许所有这些都源于我使用的Northwind40.sdf SQL Server Compact Edition 4.0数据库文件。同样,我不确定我是如何得到它的,但必须是在我设置开发环境时安装的东西。



好​​的,我怀疑这个问题与Northwind40.sdf数据库的Categories表中的字段名称有关。这些字段名称似乎有一个空格(即类别ID和类别名称)。



如果您按照所有在线演练创建一个简单的在针对此Northwind40数据库的WinForm应用程序中报告(.rdlc),其字段名称中包含空格,最终会出现如下错误:



数据集DataSet1中的字段名称为类别名称。字段名称必须是符合CLS的标识符。



我也收到了此消息,但我所做的是进入DataSet设计器并简单地重命名从类别ID到CategoryID和类别名称到CategoryName的字段。现在Visual Studio 2012没有给我任何错误。然后,这些也进入了我的报告。好吧,事实证明,这些字段从未在ReportViewer控件中显示任何数据。字段描述之所以这样,是因为它从来没有空格,我从未在数据集设计器中重命名。



我道歉我没有提到我收到的错误和我在创建原始帖子时重命名DataSet设计器中的字段。我做了很多测试和实验,我忘了我已经做过了。



我也注意到AdventureWorks2008数据库中包含的表中的大多数字段名称也没有字段名称中的空格。我怀疑这就是为什么我的所有练习报告都反对该数据源的原因。


我会做更多的实验,如果我学到了什么,我会告诉你。



我希望这会有所帮助。
Quick Solution: Field Names in tables must not have spaces in them.

Hello Everyone

I think I might know what is happening here. Indeed, perhaps all this stemmed from the Northwind40.sdf SQL Server Compact Edition 4.0 database file I was using. Again, I'm not sure how I got it but must be something that was installed when I setup my development environment.

Okay, so the problem I suspect has to do with the field names in the Categories table of the Northwind40.sdf database. These field names seem to have a space in them (i.e. 'Category ID' and 'Category Name').

If you follow all the walkthroughs online to create a simple Report (.rdlc) in a WinForm application against this Northwind40 database with its field names with a space in it, you will eventually get an error like this:

A field in the dataset ‘DataSet1’ has the name ‘Category Name’. Field names must be CLS-compliant identifiers.

I was also getting this message but what I did was go into the DataSet designer and simply rename the bad fields from 'Category ID' to 'CategoryID' and 'Category Name' to 'CategoryName'. Now Visual Studio 2012 didn't give me any errors. These, then, went into my reports as well. Well, as it turns out, those fields never showed any data in the ReportViewer control. The field 'Description' did because it never had a space in it and I never renamed it in the Dataset Designer.

My apologies I failed to mention the error I received and the renaming of the fields in the DataSet designer when I made my original post. I was doing so many tests and experiments that I forgot I had done that.

I also noticed most fields names in the tables included in the AdventureWorks2008 database also do not have spaces in their field names. I suspect that is why all my practice reports worked against that data source.

I will do some more experiments and if I learn anything else I will let you know.

I hope this helps.


这篇关于报表查看器不显示嵌入式.RDLC报表中的选定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆