We help IT Professionals succeed at work.
Get Started

VB Crystal Reports and datasets

435 Views
Last Modified: 2013-12-25
Hi,

I struggled for a day to get a Crystal Report to work. The report was simple, there is a statement header and many statement lines.

I created the dataset and used it in Crystal Reports within VS2008.

I eventually got the report to work using the following code but there must be a better way! Basically I am loading 2 tables to a dataset individually before calling the report. This is not really a problem for 1 or 2 tables but what if I want to use 5 or 6. This cannot be right. Help!

Thanks in advance

LiquidChrome
Dim qryHDRS As String = "SELECT      * FROM StatementHeaders  where shid=" & shid
        Dim qryLINES As String = "SELECT      * FROM StatementLines  where slshid=" & shid 
        Dim cmdHDR As New SqlCommand(qryHDRS)
        Dim cmdLINES As New SqlCommand(qryLINES) 
        Dim daHDRS As New SqlDataAdapter(qryHDRS, cnn1)
        Dim daLINES As New SqlDataAdapter(qryLINES, cnn1) 
        Dim myds As New GZStatementsDataSet
        Dim CrystalReport1 As New rptCustomerStatement 
        DBOpen()
        cmdHDR.Connection = cnn1
        cmdLINES.Connection = cnn1 
        daHDRS = New SqlDataAdapter(qryHDRS, cnn1)
        daLINES = New SqlDataAdapter(qryLINES, cnn1) 
        daHDRS.Fill(myds, "StatementHeaders")
        daLINES.Fill(myds, "StatementLines") 
        CrystalReport1.SetDataSource(myds)
        'CrystalReportViewer1.ReportSource = CrystalReport1 
        If pdf = False Then
            CrystalReport1.PrintOptions.PrinterName = PrintDialog1.PrinterSettings.PrinterName
            CrystalReport1.PrintToPrinter(1, True, 1, 0)
            CrystalReport1.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fname)
        Else
            CrystalReport1.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fname)
            'CrystalReportViewer1.ReportSource = CrystalReport1
        End If 
        DBClose()

Open in new window

Comment
Watch Question
Top Expert 2009
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE