Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: C# Crystal Reports Logon to SubReports Post Reply Post New Topic
Author Message
J.J.
Newbie
Newbie


Joined: 08 Dec 2009
Online Status: Offline
Posts: 9
Quote J.J. Replybullet Topic: C# Crystal Reports Logon to SubReports
    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?


Edited by J.J. - 01 Nov 2013 at 8:06am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet 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
IP IP Logged
J.J.
Newbie
Newbie


Joined: 08 Dec 2009
Online Status: Offline
Posts: 9
Quote J.J. Replybullet Posted: 10 Dec 2009 at 11:51am
Thanks for the help hilfy.

I was able to use the example from 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?


IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet 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 - 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

IP IP Logged
J.J.
Newbie
Newbie


Joined: 08 Dec 2009
Online Status: Offline
Posts: 9
Quote J.J. Replybullet 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);?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet 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:
 
 
Click on Crystal Reports .NET SDK.
 
-Dell
 
 
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.