Print Page | Close Window

C# Crystal Reports Logon to SubReports

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=8590
Printed Date: 27 Apr 2024 at 5:27am


Topic: C# Crystal Reports Logon to SubReports
Posted By: J.J.
Subject: C# Crystal Reports Logon to SubReports
Date Posted: 08 Dec 2009 at 11:20am
In Visual Studio 2008 for C#, I have a report that has a Form1.cs. That
form has a button to open another form called "frmSub Reports.cs" that
has a CrystalReportViewer embedded called "crySub Report.rpt"
private void btnCheckRegister_Click(object sender, EventArgs e)        {            frmSub_Report frmSub_Report = new frmSub_Report();            frmSub_Report.Show();        }
I'm
using a ODBC database on a AS400. For all my other Forms with Crystal
Reports, it asked for a Database Login. I'm able to Login successfully
to all other forms except the Crystal Report with SubReports in them.

I know I need to somehow do a loop to logon to every SubReport before the report is pulled but I don't know how.Can you please help?



Replies:
Posted By: hilfy
Date Posted: 10 Dec 2009 at 10:39am
I don't have sample code on this computer that I can give you, but the basic logic is:
 
1.  Loop through the sections on the report.
2.  Loop through the objects in the section.
3.  If the object is a subreport, loop through the tables and set the logins as you do for the main report.
 
I hope this helps!
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: J.J.
Date Posted: 10 Dec 2009 at 11:51am
Thanks for the help hilfy.

I was able to use the example from http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-dynamic-login.htm - C# Crystal Reports Dynamic Logon parameters. However it's not really secure.

If you have an example code for the looping, I would appreciate it.

How do you use the embedded Crystal Report instead of the File Path on your hard drive?




Posted By: hilfy
Date Posted: 10 Dec 2009 at 11:58am

To use an embedded Crystal, you can't just use a generic ReportDocument, you have to use an object that's and instance of the report type in from your project.

I have sample code for this on my website - http://www.geocities.com/geekgurl7/sample_code.html - www.geocities.com/geekgurl7/sample_code.html - look for the BOEUserAudit link in the middle of the page.  The whole project is for doing license auditing for BusinessObjects, but it uses Crystal Reports that are embedded in the project and a single viewer form that will load any of them depending on the parameters the viewer form is created with (I overrode the constructor for the form...)

-Dell



-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: J.J.
Date Posted: 10 Dec 2009 at 2:12pm
So there is not a easy way to load an embedded document?

Whenever I create a new Form, I load a CrystalReportViewer onto it. On the top right corner, there is a arrow that you can click on and a menu expands. I select "Choose a Crystal Report". I select a Crystal Report and it embedds automatically.

However, with the cryRpt.Load("C:\\file path\\crystreport.rpt"); code, it forces you to select it from your hard drive.

Is there a code that does cryRpt.Load(embedded report);?


Posted By: hilfy
Date Posted: 10 Dec 2009 at 2:38pm

Part of what you're running into are the differences between the ReportDocument and ReportViewer object models.  You're used to using the ReportViewer model but the code that you found uses the ReportDocument model.

The ReportDocument.Load method does not have a version that will connect to a report inside a project.
 
If you've added the report to the viewer, you may be able to use the ReportSource of the viewer to get to the subreports.  I'm not sure because I always use ReportDocument.
 
You can get more information about the differences between the two object models here:
 
http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/devsuite.htm - http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/devsuite.htm
 
Click on Crystal Reports .NET SDK.
 
-Dell
 
 


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window