troubles with subreport in Crystal report

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I have made a cr with a few sections with subreports and I get the data from an SQL database with manually made commands in the report wizard. In this report I get dialog-boxes up to be able to enter variables to the commands at run-time. And if I load the report with this code it works great.
VB.NET:
         Dim crp As New CrystalReport3
         Me.CrystalReportViewer1.ReportSource = crp
         Me.CrystalReportViewer1.RefreshReport()

But I wanted to be able to choose the location of my database at runtime, then I tried several methods and this code seamed to work with a report without subreports.

VB.NET:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class CR

   
    Private Sub CR_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim crtableLogoninfos As New TableLogOnInfos()
        Dim crtableLogoninfo As New TableLogOnInfo()
        Dim crConnectionInfo As New ConnectionInfo()
        Dim CrTables As Tables
        Dim CrTable As Table
        Dim TableCounter


        Dim crReportDocument As New CrystalReport1()

        With crConnectionInfo
            .ServerName = "SQLEXPRESS"
            .DatabaseName = "Kalkyle1"
            .UserID = "User2"
            .Password = "user2"
        End With


        CrTables = crReportDocument.Database.Tables

     
        For Each CrTable In CrTables
        

            Try
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
                CrTable.Location = "db_owner" + ".dbo." + CrTable.Name
            Catch ex As Exception
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            End Try


        Next

        'Set the viewer to the report object to be previewed. 

        CrystalReportViewer1.ReportSource = crReportDocument
        '***************************************************************************
       
     
    End Sub
End Class

But when I try to load my big report with all the sub reports it uses a very long time load the report, then I finally get my first dialog-box up to enter a value for the first sub-report, then I enter the value and I get an error about invalid argument for database. and the report is completely blank. anyone here has experience with this kind of sub-reports?
 
Hi,

Having the same error when running Crystal Report with sub report to MS Access Database on ASP.Net web page.
No errors when running the same report directly from Crystal Report 2008 IDE. I am using OLE DB connection to build crystal report.

Check if your sub report has any Commands. Try to delete this command and run the report again.
I know it does not make any sense, because you might need Command object to run SQL query. Here is the work around.

Instead of command - create a Query (MS Access database) or Stored Procedure (SQL Server) with all required parameters.
When you add this stored procedure on your sub report you will see all parameters under Parameter Fields on Crystal Report field explorer.
Place parameter field on sub report designer and now you can link parameters to the main report.

Hope this resolve the issue.

Serghei
 

Latest posts

Back
Top