cancel
Showing results for 
Search instead for 
Did you mean: 

auto refresh crystal reports in visual studio 2010

Former Member
0 Kudos

Hi Guys

I'm developing a simple database application in visual studio 2010. My problem is that after updating the database, the report doesn't always display the new values; for example, after 10 updates I might have to manually press the reset button twice. There's no rhyme or reason to this. Is there any code I can insert so the report automatically refreshes each time it loads up?

Any assistance would be much appreciated

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

Uncheck the 'Saved data with report' oprion from report.

Add 'CrReportDocument.Refresh()' just after you load the report.

- Bhushan

Former Member
0 Kudos

Hi Bhushan

Thanks for response.

Basically, I've have   "FormOne", that I've added a CrystalReportViewer to, that will display "CrystalReportOne"

I believe 'Saved data with report' is already unchecked

Could you please elaborate on how I could integrate your code into my solution?

Regards

Marcus

0 Kudos

Hello,

Would help to know what version of CR and VS you are using but basically something like this:

rpt.Load(rptName.ToString(), OpenReportMethod.OpenReportByTempCopy);

// set your database log on info here

rpt.Refresh();

crystalReportViewer1.ReportSource = rpt;

Don

Former Member
0 Kudos

Hi Don

I'm using visual studio 2010, but unsure of the CR version

Basically, I've got a blank form that I've added a crystal report viewer to

When Im asked to specify a CR for the control, I choose "ReportOne.rpt"

(UseReportDocument checkbox in ticked)

Something called "ReportOne1" automatically appears at the bottom of the form.

I couldn't match your suggested code with the variables I have.

Any further advice would be much appreciated

Marcus

Answers (1)

Answers (1)

0 Kudos

Hi Marcus,

Please add the following code after when you loaded your report and before showing or printing the data.

// This clears the cache so report retrieves new data from database

            if (reportDocument.HasRecords || reportDocument.HasSavedData)

            {

                reportDocument.ReportClientDocument.RowsetController.Refresh();

            }

This should clear your current data and allow for retrieving new data.

With kind regards,

Pieter Jong

Crystal Advice
http://www.crystaladvice.com

0 Kudos

Use my code if you are using the Report Engine or use Pieter code is you are using RAS.

Don

Former Member
0 Kudos

Private Sub CrystalReportViewer1_Load(ByVal ..... ) Handles CrystalReportViewer1.Load                                if (reportOne.HasRecords)

                       reportOne.ReportClientDocument

               End if

end sub

VS2010 didn't allow me to   add " .RowsetController.Refresh()"        

Would you be able to suggest any alternative code to make this work?

0 Kudos

Hi Marcus,

Add these assemblies to your Project:

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using CrystalDecisions.ReportAppServer.ClientDoc;

using CrystalDecisions.ReportAppServer.Controllers;

using CrystalDecisions.ReportAppServer.ReportDefModel;

using CrystalDecisions.ReportAppServer.CommonControls;

using CrystalDecisions.ReportAppServer.CommLayer;

using CrystalDecisions.ReportAppServer.CommonObjectModel;

using CrystalDecisions.ReportAppServer.ObjectFactory;

using CrystalDecisions.ReportAppServer.DataSetConversion;

using CrystalDecisions.ReportAppServer.DataDefModel;

using CrystalDecisions.ReportSource;

using CrystalDecisions.Windows.Forms;

using System.Data.SqlClient;

using System.Runtime.InteropServices;

Then you can use RAS.

CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;

When you load the report then you can assign the Report  to the ReportClientDoc:

rptClientDoc = rpt.ReportClientDocument;

Don

former_member183750
Active Contributor
0 Kudos

Just to add a tiny bit of help. I find the article How to Use The RAS SDK .NET With In-Process RAS Server very useful.

And of course the Dev help, etc.

- Ludek

Former Member
0 Kudos

Hi Ludek

Thanks for the post.

Does RAS SDK.NET come as standard with CR for VS 2010, or do I need other add-ons?

Marcus

Former Member
0 Kudos

Hi Don

I've never used RAS before.

Could you please explain how I would add those declarations to my project?

Marcus

0 Kudos

To answer both questions yes it comes with CR for VS 2010.

And go yo your Project Properties and add references and under .NET browse to all thsoe assembleis and check mark them. Make sure they are all version 13.x.x.x

Don

Former Member
0 Kudos

Hi Don

I went to Project Properties, and added about 20 references of the format CrystalDecisions.Reportxxxx

But I'm still unsure of where to insert the  USING statements (and whatever else I need to declare) to make Pieter's simple code work:

  1. if (reportDocument.HasRecords || reportDocument.HasSavedData)
  2.             {
  3.                 reportDocument.ReportClientDocument.RowsetController.Refresh();
  4.             }

Marcus

0 Kudos

Really?

Very first line of your main form...

Maybe you should start off with these samples:

http://wiki.sdn.sap.com/wiki/display/BOBJ/Crystal+Reports+for+.NET+SDK+Samples

Most connect to BOE so simply ignore that part and just load your report.

Don