cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Crystal Reports XI in SBO 2004 ?

Former Member
0 Kudos
54

Hello,

I´m making an Add-on in VB .Net and need to show a report from Crystal Reports XI (a .rpt file). My Add-on is a Console Application. From what i have read from this forum the best way is to use a Windows Form (not a form from SBO) with a "Crystal Report Viewer". How is this done exactly?

1 - What refences to include in the project?

2 - How to assign to Crystal Report Viewer to the Windows Form?

3 - How do i change in VB .Net code (that is, in runtime) the datasource from the .rpt file?

Can you please give a code example.

Thank You.

Jorge Lopes

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks

Former Member
0 Kudos

I managed to do steps 1 and 2 like this:

1 -

CrystalDecisions.CrystalReports.Engine

CrystalDecisions.Windows.Forms

2 -


Imports CrystalDecisions.CrystalReports.Engine

Module ImpressaoCrystalReports

    Private Class FrmCrystalReportViewer
        Inherits System.Windows.Forms.Form

        Public objCrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer

        Public Sub New()
            MyBase.New()
           
            objCrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer

            Me.Controls.Add(objCrystalReportViewer)
         End Sub

    End Class

    Public Sub MostraRelatorioCrystal()
        Try
            Dim frmCRV As FrmCrystalReportViewer = New FrmCrystalReportViewer

            frmCRV.objCrystalReportViewer.ReportSource = strPath & "ORCAMENTO.rpt"
            
            frmCRV.ShowDialog()

        Catch ex As Exception
            objApplication.MessageBox(ex.Message)
        End Try
    End Sub

End Module

3 - ?

Any comments or suggestions?

Jorge Lopes

Former Member
0 Kudos

Hi Jorge,

to change the report datasource we use this code:

Dim crtableLogoninfos As New TableLogOnInfos
            Dim crtableLogoninfo As New TableLogOnInfo
            Dim crConnectionInfo As New ConnectionInfo
            Dim CrTables As Tables
            Dim CrTable As Table
With crConnectionInfo
                .ServerName = Servidor
                .DatabaseName = BD
                .UserID = Usuario
                .Password = Pass
            End With
CrTables = CR.Database.Tables

            'Loop through each table in the report and apply the 
            'LogonInfo information 

            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next

Hope helps,

Ibai Peñ

Former Member
0 Kudos

Thanks Ibai.

My code to change DataSource is:


 Try
                Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument

                rpt.Load(strPath & RELATORIO_ORCAMENTO)

                '/ Inicio
                Dim rptTableLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
                Dim rptConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
                Dim rptTables As CrystalDecisions.CrystalReports.Engine.Tables = Nothing
                Dim rptTable As CrystalDecisions.CrystalReports.Engine.Table = Nothing

                With rptConnectionInfo
                    .ServerName = ODBC_DATASOURCE
                    .DatabaseName = objCompany.CompanyDB
                    .UserID = System.Windows.Forms.SystemInformation.UserName
                End With

                rptTables = rpt.Database.Tables
                For Each rptTable In rptTables
                    rptTableLogonInfo = rptTable.LogOnInfo
                    rptTableLogonInfo.ConnectionInfo = rptConnectionInfo
                    rptTable.ApplyLogOnInfo(rptTableLogonInfo)
                    rptTable.Location = rptTable.Location
                Next

                If (rpt.Subreports.Count > 0) Then
                    ActualizaSubReports(rpt.Subreports, rptConnectionInfo)
                End If
                '/ Fim

                rpt.SaveAs(rpt.FileName)

                rpt.Close()
            Catch ex As Exception
                objApplication.MessageBox(ex.Message)
            End Try

Jorge Lopes

Former Member
0 Kudos

And finally the code to create, in runtime, a User DSN (ODBC Datasource):


Try
            Dim key As Microsoft.Win32.RegistryKey = _
                Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SoftwareODBCODBC.INIODBC Data Sources")
            key.SetValue(ODBC_DATASOURCE, "SQL Server")

            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SoftwareODBCODBC.INI" & ODBC_DATASOURCE)
            key.SetValue("Database", objCompany.CompanyDB)
            key.SetValue("Driver", "C:WINNTSystem32sqlsrv32.dll")
            key.SetValue("Server", objCompany.Server)
            key.SetValue("Trusted_Connection", "Yes")

            Microsoft.Win32.Registry.CurrentUser.Flush()
        Catch ex As Exception
            objApplication.MessageBox(ex.Message)
        End Try

I guess that this is all you need to work with a Crystal Report in a SBO Add-on.

Jorge Lopes