Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: Sub Report data issue Post Reply Post New Topic
Page  of 2 Next >>
Author Message
o9z1
Newbie
Newbie


Joined: 01 Feb 2008
Online Status: Offline
Posts: 12
Quote o9z1 Replybullet Topic: Sub Report data issue
    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
IP IP Logged
o9z1
Newbie
Newbie


Joined: 01 Feb 2008
Online Status: Offline
Posts: 12
Quote o9z1 Replybullet Posted: 03 Feb 2008 at 11:53pm
anyone?
IP IP Logged
o9z1
Newbie
Newbie


Joined: 01 Feb 2008
Online Status: Offline
Posts: 12
Quote o9z1 Replybullet Posted: 05 Feb 2008 at 8:53pm
still not able to get this to work.  Is anyone able to help with this?
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
o9z1
Newbie
Newbie


Joined: 01 Feb 2008
Online Status: Offline
Posts: 12
Quote o9z1 Replybullet 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.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
o9z1
Newbie
Newbie


Joined: 01 Feb 2008
Online Status: Offline
Posts: 12
Quote o9z1 Replybullet Posted: 06 Feb 2008 at 10:35am
The name of the sub report is CarcassData.rpt
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
o9z1
Newbie
Newbie


Joined: 01 Feb 2008
Online Status: Offline
Posts: 12
Quote o9z1 Replybullet 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.  
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
Page  of 2 Next >>
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.032 seconds.