Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

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


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.
Posted
Updated 11-Apr-16 9:54am

1 solution

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900