Can Crystal Reports access a VB database object?

pjslevin

Member
Joined
Oct 28, 2007
Messages
10
Programming Experience
10+
I have a VB.NET program where I have to access several differnet databases. My program connects to each database a summarizes some data and fills a dataset object that I have internally created in my program. Can Crystal Reports Viewer link to to this dataset object? Or, will CR only connect to external DBs? Obviously, the records in this dataset are being created dynamically and I don't want CR viewer to try to connect as soon as my form is loaded. Instead, I want it to access the dataset object after I am finished filling it. Any suggestions? Pat
 
I have a VB.NET program where I have to access several differnet databases. My program connects to each database a summarizes some data and fills a dataset object that I have internally created in my program. Can Crystal Reports Viewer link to to this dataset object? Or, will CR only connect to external DBs? Obviously, the records in this dataset are being created dynamically and I don't want CR viewer to try to connect as soon as my form is loaded. Instead, I want it to access the dataset object after I am finished filling it. Any suggestions? Pat

I knew this was possible and finally figured out how to make it work. The basics are this:

Design a report (I'm using a report built in the project). As the datasource, you can select a dataset in order to build the report. When you do this, you won't get a preview of the report that shows you real data (from the database), since the dataset isn't filled until runtime. It will show you faux data of the correct type for the fields being displayed.

Somewhere on a form, place a crystalreportviewer object. Don't bother setting the report source, as I think (others may correct) that would only work where the report is looking at a physical database. It won't hurt you to put in the source, its just a waste of time. I think you'll see why in a moment.

In the code fill the appropriate dataset as you are already doing. Create an object of type <reportname> where reportname is the name of the report you created. I believe that VS will generate that class when you develop the report.

Next, call the setdatasource method of the report object you created. Its overloaded so you have some options based on what it is your doing. You can pass it an entire dataset or just a datatable depending on the complexity of your report.

Next, set the reportsource property of the crystalreportviewer object to the report object, and it should all work.

I'm not sure if the sequence of the last two steps is critical, but I suspect it is. If you don't set the datasource until after, you may need to execute a refresh on the report. Others with more experience than I would have to tell you that.

At any rate, something to try. I am still a serious newbie at this, so caveat reporter and all that.
 
Back
Top