I often write blogs about problems that I’ve had and which, eventually, I’ve managed to solve. This is one of them.
If you’ve landed on this blog because you’ve seen this error message, you’re probably trying to create a report with the ReportViewer control. (There are other scenarios where this message might appear, but this is the one I’m working on.)
In my case, the message came up when I tried to run a fairly simple report in a Windows Form using the ReportViewer control in Visual Studio 2010.
So of course I did the usual internet search and came up with lots of forum questions and answers and other results. None of them applied to my situation though. Many of the questions had been posted before VS 2010 shipped, so users were using VS 2008. That version of Visual Studio uses a different variety of ReportViewer.
As is so often the case, the answer was very simple, with the benefit of hindsight. The cause, by the way, was that in the Report Designer I had changed the report’s data source from one data set to another. Now, the report was quite happy to accept this change and I was able to change the fields that I used in the body of the report.
But what didn’t change was the TableAdapter that the ReportViewer was relying on over in the Windows Form. So when I tried to run the project, there was a mismatch between what the Report was offering to display and what the ReportViewer thought it needed. You might have thought that this change of TableAdapter would be done automatically. I certainly did and that’s the danger with technology that does so much under the covers for you. You get lulled into a belief that everything will somehow be magically taken care of for you.
Anyway, the fix is very simple. Click on the smart tag of the ReportViewer. You will see that one of the choices is 'Choose Data Sources’.
You will then see a Choose Data Sources dialog window. Click at the right hand side of the Data Source Instance column a small arrow will appear. Click on this arrow and a new row will be created. This may have the rather unhelpful choice range of ‘(none)’ as shown below, depending on what bindings you have in place for the form.
Click at the right hand side of the Data Source Instance column again, this time inside the second row. The small arrow will appear again and you will see the beginning of a tree of elements. Navigate through the options until you find the data source you want to use.
Once you’ve correctly made the selection that matches the report that’s currently assigned to the ReportViewer, click OK. With the binding in place, run the project again and it should now run correctly and your report will be displayed.