3
votes

Im setting the report datasource in my C# code like this:

report.SetDataSource(dataSource);

And it all works but after that the crystal report still tries to connect to the database. I though that if i set the datasource from the code the report wont want to get more data from database then.

Is that really like so that even after setting the datasource from code report goes and asks more data from database?

EDIT: The real problem im facing is that i have 2 reports, one goes and fetches data from database after setting datasource from code and the other just doesn't. I have been pulling my hear all day to figure this out and no luck yet. The two reports are allmost identical, both use a database View to get the fields from database and both use the same code to set the datasource from code. The logic is that i load the report in my code, get the required database fields from it and create DataTable with those fields. Then i fill it with data and set it as datasource with this: report.SetDataSource(dataSource);. For both reports the code and logic is identical! Just the fields are different..

2
Is the second report a subreport? - Hailton
No, second report is not subreport. - hs2d
Is there a subreport in the report? My experience with this same problem has been that we thought a subreport was being suppressed under a certain circumstance so under those circumstances we didn't set the datasource for the subreport in code. It wasn't properly being suppressed in the .rpt file though so it was asking for a datasource. My guess is that this is something along those same lines. - Lee O.
There is subreport in the report... - hs2d

2 Answers

1
votes

In case if you have subreports.

loop through subreports and call SetDataSource(dataSource) on each subreport object.

0
votes
        Report.RicevutaCup r = new Report.RicevutaCup();
        System.Data.DataSet ds = CupDatasetFactory.CreaRicevutaCupDataSet(df);
        r.OpenSubreport("RicevutaCup_Prestazioni").SetDataSource(ds);

        r.SetDataSource(ds);

Solved my issue (after restarting IIS).