Solved

Refreshing Crystal Reports using a vb.net console application.

Posted on 2004-03-31
6
1,681 Views
Last Modified: 2010-08-05
 I am looking for a way to refresh a crystal report(8.0) .rpt file using a vb.net console application. I also want to save that refreshed data. Currently if you run this .rpt manually you get prompted for a database login, which I want to handle in the app as well.  I have been playing with this but have been unable to get everything to work.
  Here is what I have so far:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Module Module1
    Private reportDocument1 As CrystalDecisions.CrystalReports.Engine.ReportDocument

    Sub Main()
        reportDocument1 = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
        reportDocument1.Load("c:\test1.rpt")

        Dim logonInfo As TableLogOnInfo = New TableLogOnInfo()
        logonInfo = reportDocument1.Database.Tables(0).LogOnInfo
        logonInfo.ConnectionInfo.ServerName = "g"
        logonInfo.ConnectionInfo.DatabaseName = "accounts"
        logonInfo.ConnectionInfo.UserID = "sa"
        logonInfo.ConnectionInfo.Password = "sa"
        reportDocument1.Database.Tables(0).ApplyLogOnInfo(logonInfo)
        reportDocument1.Refresh()
    End Sub

End Module

  This doesn't appear to be actually refreshing my report. I am new to using crystal reports so I am sure I am missing a key concept here.

Chris ...
0
Comment
Question by:cwigley
6 Comments
 
LVL 2

Expert Comment

by:DonRameshSachin
ID: 10729718
Hi,
 In the report viewer itself there will be a refresh button available. U can use that button to refresh the report and whatever changes made in the database will get relected in the report viewer.

Don
0
 

Author Comment

by:cwigley
ID: 10731417
Don,

  I am looking to do this without user interaction. This is to be an automated process from start to finish. Is it possible to call this same functionality from the viewer, through code?

Chris
0
 
LVL 27

Expert Comment

by:planocz
ID: 10731676
Hi cwigley,

'Use for Logins.............

Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared

'use as global Vars.
    Public myReport As New ReportDocument        'Gobal Report Doc
    Public sReportName As String                 'Crystal Report Name from list
    Public sReportPath  as String                  'Path for your reports to load
    '**** Server Connection Vars *********
    Public sDBServer As String = "MyServer"
    Public sUSERid As String = "UserID"
    Public sDBName As String = "DBName"
    Public sDBPass As String = "APassword"
    Public Connect As SqlConnection                  'Use for msSQL
    Public SyConnect As Odbc.OdbcConnection   'Use for Sybase dbases
    Public sSQL As String

 Private Sub GetReportConnection(ByVal myReport)
        ' Objects used to set the proper database connection information
        Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
        Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

        Try
            ' Load the report
            myReport.Load(sReportPath & sReportName, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy)

            ' Set the connection information for all the tables used in the report
            For Each tbCurrent In myReport.Database.Tables
                tliCurrent = tbCurrent.LogOnInfo
                With tliCurrent.ConnectionInfo
                    .ServerName = sDBServer
                    .UserID = sUSERid
                    .Password = ""
                    .DatabaseName = sDBName
                End With
                tbCurrent.ApplyLogOnInfo(tliCurrent)
            Next tbCurrent
        Catch Exp As LoadSaveReportException
            MsgBox("Incorrect path for loading report.", _
                    MsgBoxStyle.Critical, "Load Report Error")
        Catch Exp As Exception
            MsgBox(Exp.Message & "   in GetReportConnection Procedure", MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:cwigley
ID: 10735903
Planocz,

  Your code does about the same thing that mine already does. It still does not get me to the point of actually refreshing and saving this report. That is the part that I am stuck with.
0
 
LVL 13

Accepted Solution

by:
EwaldL earned 125 total points
ID: 10736421
saving a report is done by exporting, ie with .net 2003
Dim rpt As New ReportDocument rpt.Load("c:\\yourreport.rpt");
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, "c:\export\yourreport.pdf")
(from http://support.businessobjects.com/library/kbase/articles/c2013529.asp)

or .net 2002
http://support.businessobjects.com/library/kbase/articles/c2010264.asp

you can chose different file types, such as .rpt, .pdf, .doc or others. the available options depends on whether you are also using the full crystal reports 9 or 10 (developer or advanced edition)
0
 

Author Comment

by:cwigley
ID: 10736503
Ewaldl,

  Thank you. That is exactly what I was looking for!

Chris
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

16 Experts available now in Live!

Get 1:1 Help Now