Know your ISP.

breath-hyenas
User #19884   2737 posts
Whirlpool Forums Addict

Hi,

I've created a Microsoft Report (not Crystal Report) in C# .NET along with a datasource/dataset (through the right hand pane of Visual Studio) which i have set up with a report viewer on one of my forms and have confirmed is working. However, i would like to be able to dynamically change it's datasource at runtime so that the report can connect to a similar table in another database. How can i do this? Is it possible?

Thanks,
Adam

posted 2009-Jul-2, 7pm AEST
User #29222   738 posts
Whirlpool Enthusiast

you need to use a dataset/datatable or some other object that you dynamically fill from a database.

In your program instantiate and populate the dataset/datatable by using a query to the appropriate database and table and then set this "dynamic" datasource as the datasource of your report.

Cheers
Aaron

posted 2009-Jul-2, 10pm AEST
User #19884   2737 posts
Whirlpool Forums Addict

Hi Aaron,

Yeah i thought that's how you would do it, but i have no idea what the code would be, and how i would bind the report to it? I've tried googling but have found nothing...

Thanks again,
Adam

posted 2009-Jul-2, 10pm AEST
User #80502   259 posts
Forum Regular

Your talking about the windows reports (.rdlc) I assume? Ignore this if you arnt.

The way I use them is:
1) Create an object (class) in my application which is to be the datasource for the report. Each "field" will be shown by a property of the class.
2) Add this class to the "Datasources" thing.
3) Write report based on the class (or classes if I need multiple datasources)
4) Whenever I run the report, I write code in C# to retreive the data from the database, and then populate the data in a list of the class, and pass this list to the report.

If I need to change the datasource, this is all done at step 4 – I retreive different data (either from a different database, different tables, or different criteria) from the database and use this to populate the list I pass to the report.

posted 2009-Jul-3, 9am AEST
User #19884   2737 posts
Whirlpool Forums Addict

Thanks Shaggs. Yes i am talking about windows reports. I understand the idea behind it, but i have no idea how to code it and havn't had any luck searching online. Any chance you could show me the code you use or part of it? Just something to get me started then i can take it from there. Thanks.

posted 2009-Jul-3, 4pm AEST
User #80502   259 posts
Forum Regular

Yes – there is very little documentation for windows reports. We use mostly crystal reports for our app, and only windows reports when the data needs to be manipulated in our (C#) app before it is printed, purely because crystal reports is better documented.

As far as documentation goes, the best guide I have found is this: http://www.gotreportviewer.com/

A few others (which I dont think I used much):
http://www.devx.com/dotnet/Article/30424
http://msdn.microsoft.com/en-us/library/ms252067.aspx

Super Fast Penguin writes...

I understand the idea behind it, but i have no idea how to code it

What do you mean by this? You mean creating the actual report, or passing data to it?

posted 2009-Jul-3, 4pm AEST
User #19884   2737 posts
Whirlpool Forums Addict

Shaggs writes...

As far as documentation goes, the best guide I have found is this: http://www.gotreportviewer.com/

Perfect mate, thanks heaps... just what i was looking for. Thanks for all the help.

Adam

posted 2009-Jul-4, 1pm AEST
Hosted by
Bulletproof Networks
Big numbers
1,256,837 threads
23,064,146 posts
2,524,683 whims sent
3,598 wiki topics
228 ISPs listed
9,682 broadband plans
991 modems & routers
48,891 features filled