Print Page | Close Window

Sub Report data issue

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=2200
Printed Date: 18 May 2024 at 3:41pm


Topic: Sub Report data issue
Posted By: o9z1
Subject: Sub Report data issue
Date Posted: 01 Feb 2008 at 6:22am
 I have created a main report and a sub report, which both work fine by
themselves. When I insert the 2nd report as a sub report, the main
report still contains data, but the sub report is blank. I think the
problem is with my code. Could anyone evaluate my code or provide a
link to an example of how to do this. This is my first shot at sub
reports.
Dim strReportPath1 As String = "PCMarketException"
Dim strConnection As String = "Data Source=HERCULES;Initial Catalog=Carcass2;Integrated Security=True"
Dim Connection As New SqlConnection(strConnection)
Dim strSQL As String = "VERY VERY LONG SQL Statement(I won't list all of this out)"
Dim strSQL1 As String = "SELECT * FROM t_groupdata"
Dim DA As New SqlDataAdapter(strSQL, Connection)
Dim DA1 As New SqlDataAdapter(strSQL1, Connection)
Dim DS As New DataSet

DA.Fill(DS, "PCMarket")
DA1.Fill(DS1, "CarcassData")

Dim strReportPath As String = Application.StartupPath & "\" & strReportPath1 & ".rpt"

If Not IO.File.Exists(strReportPath) Then
'Throw (New Exception("Unable to locate report file:" & vbCrLf & strReportPath))
strReportPath = Application.StartupPath & "\..\..\" & strReportPath1 & ".rpt"
End If

Dim cr As New PCMarketException
cr.Load(strReportPath)
cr.SetDataSource("PCMarket")
cr.Subreports.Item("CarcassData").SetDataSource(DS1)

cvwPCMarket.ShowRefreshButton = False
cvwPCMarket.ShowCloseButton = False
cvwPCMarket.ShowGroupTreeButton = False
cvwPCMarket.ReportSource = cr



Replies:
Posted By: o9z1
Date Posted: 03 Feb 2008 at 11:53pm
anyone?


Posted By: o9z1
Date Posted: 05 Feb 2008 at 8:53pm
still not able to get this to work.  Is anyone able to help with this?


Posted By: BrianBischof
Date Posted: 05 Feb 2008 at 10:04pm
Try this to set the datasource of a subreport:

cr.OpenSubreport("CarcassData").SetDataSource(DS1)



-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: o9z1
Date Posted: 06 Feb 2008 at 7:22am
I tried that and got an error:
Object reference not set to an instance of an object

On the line you just provided.


Posted By: BrianBischof
Date Posted: 06 Feb 2008 at 9:26am
That's because it can't find the subreport and returns a null object. Debug your app to make sure that you have the subreport name correct.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: o9z1
Date Posted: 06 Feb 2008 at 10:35am
The name of the sub report is CarcassData.rpt


Posted By: BrianBischof
Date Posted: 06 Feb 2008 at 10:40am
Look at the report objects collection (in debug mode) and find the subreoprt object. Then look at it's Name property. This is what you need to pass to the OpenSubreport() method. I won't go into here, but in my .NET book I discuss three different ways that CR has for showing a subreport name. The only one that is valid is the one that is assigned to the Name property in the object model.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: o9z1
Date Posted: 06 Feb 2008 at 12:23pm
Shows how new to this I am, but I am not even sure where I can see the report objects collection.  Forgive my lack of knowledge on this.  


Posted By: BrianBischof
Date Posted: 06 Feb 2008 at 3:55pm
Hmmm... well, this will be tough to debug if you are brand new to the object model. Pretty soon I'll be putting chapters to my .NET 2005 book online and you should subscribe to that to learn more about CR and runtime manipulation. I cover this stuff in my original CR.NET book, but that was for version 2003. Anyway, here is some quick code from my book. This should help get you on the right track. it's not complete (I have to much work to do), but pretty close.
for each myReportObject in myReport.ReportDefinition.ReportObjects
if myReportOjbect.Kind = CrystalDecisions.[Shared].ReportObjectKind.SubreportObject Then
  'Use debug mode here to examine the Name property of the subreport
End If
Next





-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: o9z1
Date Posted: 08 Feb 2008 at 6:36am
in the above code you provided It won't compile at this part:

myReportObject.Kind  'kind is not a member of project.



Print Page | Close Window