Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good tutorial for using Crystal Reports with .NET? 3

Status
Not open for further replies.

artyk

Programmer
Apr 5, 2006
163
US
I am trying to feel my way through setting up reports with my VB app. I have tried Crystal and regular reports and I'm not getting any data in either. Is there a good tutorial anyone knows of that might be helpful? I have looked at the Microsoft/MSDN guide, but it didn't address my absence of data. Thanks in advance.
 
Tek-Tips forums

Business Objects: Crystal Reports 1 Formulas
Business Objects: Crystal Reports 2 Data Access
Business Objects: Crystal Reports 3 Integrate
Business Objects: Crystal Reports 4 Other topics
 
Actually I asked my questions about CR over there first and no one seemed quite sure what the problem was. I think many of the people in that forum arent using .NET. I came here because I thought some here would be, but if I can just find a good tutorial, I think I could sort everything out. Thanks.
 
There is a lot of sample code included with not only .net, but Crystal Reports as well. If that doesn't help, search of the Business Objects Knowledge Base. From my experience, CR is much easier to do in .net than VS 6.

I hope that helps!
Brett
 
The issue I'm having at the moment is I'm trying to set up a simple report that pulls data from 2 tables. The first lists surgeon ID, surgeon name, and specialty ID (which is linked to a table that lists specialty ID and specialty description). When I run through the report wizard and select what I want to use from the "Project Data Sources" node I can see my dataset and the tables and fields that are in it, however, when I try to browse the data I get nothing and when I view the report I either get just my headings, or sometimes some "dummy" data that seems to be inserted to be a representation of what the finished report should look like. Is there anything that is obvious that I am doing wrong? Is there a better way to set up my data source? I would even settle for a regular report at the moment, but I am having similar problems with that.
 
artyk,

It took me a while to figure out the basics of CR and I was running into the same problem you have run into. I'm still a CR novice but I'll try and help.

When you create a report CR uses your dataset to design the report but it doesn't use the data when you run the report, you have to set the reports datasource to your dataset.

something like

Code:
Dim customerReport As ReportDocument = New ReportDocument
customerReport.Load(Application.StartupPath & "\" & "Report.rpt")
customerReport.SetDataSource(YourDataSet)
' print the report
customerReport.PrintToPrinter(1, False, 0, 0)
' display the report in a cr viewer
CrViewer.ReportSource = customerReport

You can put the code in the formload method if you are using a report viewer or in a button if you want to print.

I never really found a good tutorial for a beginner and I spent a lot of time looking. Check out the samples that are installed with VS located in
C:\Program Files\Microsoft Visual Studio 8\Crystal Reports


I hope this helps
Perrin
 
Thanks! I will try that. It's good to know I'm not the only one that had that problem. I was starting to wonder. Thanks again! I'll update you as soon as I can.
 
No luck so far. I looked at some of the examples and they appear to be set up similarly to mine, but they get data and I still don't. I will try to look over more of the examples over the weekend and see if I find anything. Could it be something in the way I set up the data with the wizard? Is the "Project Data" not good enough? What I mean by that is would I still have to go in and set up a special OLE DB connector for SQL?
 
kliot,
I have a question about the line "customerReport.SetDataSource(YourDataSet)". I typed it how I thought it should be for my program, which is "surgeonReport.SetDataSource(CaseInputDataSet)", but I get an error that says "'CaseInputDataSet' is a type and cannot be used as an expression." What did I do wrong? I'm also trying to look at the examples that came with VS, but some of those are more complex than what I need. It seems like this should be easy, maybe it's just me.
 
Not sure what's wrong, can you post more of your code? Where does the dataset CaseInputDataSet come from? Stick with it I'm sure you're close to getting things working.

Perrin
 
kliot,
I have a book that I bought awhile back because I'm pretty new to VS 2005. It gave some direction with Crystal Reports, but when I followed the step-by-step I ended up where I am currently. The example in the book actually didn't contain any code for the report or the viewer. Basically it took me through the CR wizard, then showed how to put the viewer on the form and how to add a ReportDocument to the form. Then it said to set the ReportSource to the report you want to display and it should work. It gave some code samples for some other report functions, but not for displaying a basic report. I will need code eventually because I'm going to have the same viewer display many reports, but I'm just trying to get one to work right now. I checked out the link that dragganss provided, but I haven't been able to get the code to work with what I have so far. Also, the dataset CaseInputDataSet is the dataset that my app uses to add records to my tables. I wasn't sure if I needed to set up a new dataset or if I should be able to use the same one. Thanks.
 
You already have all the code you need we just need to figure out where the problem is. I'm pretty sure it's your dataset. You certainly an use the same dataset that your app uses.

Are you working with a new form in your app? Is the dataset associated with that form? For example does the dataset icon show up when you view the form.vb[design]. If you are not sure simply go to your "Data Source" ([Data -> Show Data Sources] from the menu) and drag table or even just a column to the form and VS will create the dataset for you. Then set your report's datasoure to that dataset.

You're so close to getting it to work don't give up, again I'm not much more than a novice myself so I kind of feel like Stevie Wonder trying to teach Ray Charles how to drive.

Perrin
 
That's a funny analogy! I haven't added my dataset to my form yet. I will try that and let you know. Thanks!
 
Still no luck. Here's the code I have right now (CaseInputDataSet has been added to the form).

Code:
Private Sub frmReportView_Load(byVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim surgeonReport As ReportDocument = New ReportDocument
surgeonReport.Load(Application.StartupPath & "\" & "Surgeons.rpt")
surgeonReport.SetDataSource(CaseInputDataSet)
CrystalReportViewer1.ReportSource = surgeonReport
End Sub

I still get my headings (which don't come from the database), but nothing else. Should there be something about the ReportDocument in there or is that optional?
 
Are you still getting the error "'CaseInputDataSet' is a type and cannot be used as an expression?"

I can't think of anything else that should be in there. I'll think about it some more when I get a chance.

Perrin
 
No, adding it to the form fixed that error. I didn't realize I had to have an instance of it on the report form. Thanks for that tip.
 
Good, now that we have the dataset connected to the report I'm thinking that the dataset is empty. Are you filling the dataset somewhere?

The tables that are used on the report must be filled with the appropriate records.

eg:
SurgeonTableAdapter.Fill(CaseInputDataSet.Surgeons)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top