Solved

crystal reports XI sp 2 called from VB.Net 2008

Posted on 2010-11-15
7
301 Views
Last Modified: 2012-06-21
In a VB.Net project, the code below comes from my main form.  It calls a second form, fCRV which has a single control, a crystal report viewer (crvMain).  There are two different reports involved.

I need to modify this code such that I set the log on information for the crystal report (server, database, no integrated security, user id, and password).  Both reports use the same connection information.

How is that done in VB.Net (2008)?

Thanks.
Public Shared Sub PrintReport(ByVal f As Form1)

        Try

            Dim vchrNo As String



            'qty mode report is called: ReceiverVariance-CR11.rpt -- change config to QtyModeReport

            'voucher mode report is called: APVoucherRecapReport-CR11 -- add to config VoucherModeReport



            If Globals.QtyModeIndicator = True Then

                fCRV.crvMain.ReportSource = Globals.QtyModeRept

                'if clicked, let the report ask for a parameter else pass it a selection formula

                If Not Globals.ReportCalledByClick Then

                    fCRV.crvMain.SelectionFormula = "{ag_ap_match_variance_report.pack_no} = " & Chr(34) & f.billNo.Text & Chr(34)

                End If

                fCRV.ShowDialog()

            Else

                fCRV.crvMain.ReportSource = Globals.VoucherModeRept

                'if clicked, let the report ask for a parameter else pass it a selection formula

                'get voucher number

                Dim dr As DataGridViewRow = f.dgvVouchers.SelectedRows(0)

                VchrNo = dr.Cells(1).Value.ToString



                If Not Globals.ReportCalledByClick Then

                    fCRV.crvMain.SelectionFormula = "{aptrxfil_sql.vchr_no} = " & Chr(34) & vchrNo & Chr(34)

                End If

                fCRV.ShowDialog()

            End If

        Catch ex As Exception

            Throw New Exception(ex.Message)

        End Try

    End Sub

Open in new window

0
Comment
Question by:g_johnson
  • 4
  • 3
7 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 34139298
This is one of the most asked questions here.  Unfortunately what works for one report doesn't always work for another.

One way around this is to pass the report a dataset.
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx

Does the report run if you provide the connection information when asked?

mlmcc
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34139359
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 34139383
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:g_johnson
ID: 34148958
Hello mimcc.

I can't use a dataset; that part's out of my control.  I'm trying to invoke several, pre-written reports.  Given my code attached, whereby I set the report viewer source to a certain report, I can't figure out how to reference any of the properties or methods.

For example:
            Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
            For Each tbCurrent In fCRV.crvMain.DataBase

is not available to me.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34176284
What references have you added to the application for Crystal?

Is this Crystal XI R2?

mlmcc
0
 
LVL 4

Author Comment

by:g_johnson
ID: 34176550
Ultimately I solved it like this:
    Public Shared Sub PrintReport(ByVal f As Form1)
        Dim i As Integer
        Dim ii As Integer
        Dim iii As Integer
        Dim vchrNo As String
        Dim connInfo As New CrystalDecisions.Shared.TableLogOnInfo()
        Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim subReportObj As CrystalDecisions.CrystalReports.Engine.SubreportObject
        Dim subReportDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument

        Try

            If Globals.QtyModeIndicator = True Then
                objReport.Load(Globals.QtyModeRept)
            Else
                objReport.Load(Globals.VoucherModeRept)
            End If

            'set connection info
            connInfo.ConnectionInfo.UserID = "sa"
            connInfo.ConnectionInfo.Password = "amergroc2004"
            connInfo.ConnectionInfo.ServerName = Globals.ServerName
            connInfo.ConnectionInfo.DatabaseName = Globals.DatabaseName

            For i = 0 To objReport.Database.Tables.Count - 1
                objReport.Database.Tables(i).ApplyLogOnInfo(connInfo)
            Next

            For i = 0 To objReport.ReportDefinition.Sections.Count - 1
                For ii = 0 To objReport.ReportDefinition.Sections(i).ReportObjects.Count - 1
                    With objReport.ReportDefinition.Sections(i)
                        If .ReportObjects(ii).Kind = ReportObjectKind.SubreportObject Then
                            subReportObj = CType(.ReportObjects(ii), CrystalDecisions.CrystalReports.Engine.SubreportObject)
                            subReportDoc = subReportObj.OpenSubreport(subReportObj.SubreportName)
                            For iii = 0 To subReportDoc.Database.Tables.Count - 1
                                subReportDoc.Database.Tables(iii).ApplyLogOnInfo(connInfo)
                            Next
                        End If
                    End With
                Next
            Next

            'qty mode report is called: ReceiverVariance-CR11.rpt -- change config to QtyModeReport
            'voucher mode report is called: APVoucherRecapReport-CR11 -- add to config VoucherModeReport

            If Globals.QtyModeIndicator = True Then
                '                fCRV.crvMain.ReportSource = Globals.QtyModeRept

                'if clicked, let the report ask for a parameter else pass it a selection formula
                If Not Globals.ReportCalledByClick Then
                    objReport.RecordSelectionFormula = "{ag_ap_match_variance_report.pack_no} = " & Chr(34) & f.billNo.Text & Chr(34)
                    'fCRV.crvMain.SelectionFormula = "{ag_ap_match_variance_report.pack_no} = " & Chr(34) & f.billNo.Text & Chr(34)
                End If
                'fCRV.ShowDialog()
            Else
                '                fCRV.crvMain.ReportSource = Globals.VoucherModeRept
                'if clicked, let the report ask for a parameter else pass it a selection formula
                'get voucher number
                Dim dr As DataGridViewRow = f.dgvVouchers.SelectedRows(0)
                vchrNo = dr.Cells(1).Value.ToString

                If Not Globals.ReportCalledByClick Then
                    objReport.RecordSelectionFormula = "{aptrxfil_sql.vchr_no} = " & Chr(34) & vchrNo & Chr(34)
                    'fCRV.crvMain.SelectionFormula = "{aptrxfil_sql.vchr_no} = " & Chr(34) & vchrNo & Chr(34)
                End If
                'fCRV.ShowDialog()
            End If

            fCRV.crvMain.ReportSource = Nothing

            fCRV.crvMain.ReportSource = objReport

            fCRV.ShowDialog()
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub


Thanks for pointing me in the right directon.
0
 
LVL 4

Author Closing Comment

by:g_johnson
ID: 34176554
Definitely pointed me in the right direction
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Copy/Clone an object. 9 30
Close word object 13 38
Search and display values in the textbox using VB.net and SQL 19 34
How to use odbc in vb to connect to ms sql 14 40
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now