Solved

How to use Crystal Reports in VB.NET

Posted on 2006-07-13
1
348 Views
Last Modified: 2010-04-23
Hi

I would like to create a report based on a database query using a windows form programmed with vb.net.

How can I do this using crystal reports in vs.net 2003?

I simply want to query the database and display it in crystal report format on the form.

Thanks

narmi
0
Comment
Question by:narmi2
1 Comment
 
LVL 2

Accepted Solution

by:
cwile earned 500 total points
ID: 17098927
I made all of the reports in crystal reports and saved them off onto a network share in their .rpt format making sure to NOT save data with report when I was complete.
You can hook up whatever database/query to the report at time of creation in crystal reports. Just be sure if you use DNS that the target machine has the same DNS.
I then wrote a small app in VB.net that opens a dialogue box, the user selects the report, it then opens the report using the crystal report viewer the user then puts in their selection criteria into the crystal report (or can you already have your query doing that). All you need to add to your form is the crystal report viewer

Here's the code my app uses:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim openDialog As New OpenFileDialog
        Me.Cursor = Cursors.WaitCursor
        openDialog.DefaultExt = "rpt"
        openDialog.Filter = "Report Files(*.RPT)|*.rpt|All Files(*.*)|*.*"

        Try
            If openDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                sReport = openDialog.FileName
                loadReport()
                Me.Cursor = Cursors.Default
            Else
                Me.Cursor = Cursors.Default
                End
            End If

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            MsgBox(ex)
            Me.Cursor = Cursors.Default
            End
        End Try

    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        cView.Height = Me.Height - 30
        cView.Width = Me.Width - 10
        cView.Left = 0
        cView.Top = 0
    End Sub


    Private Sub loadReport()

        Dim cRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
        cView.ReportSource = sReport
        cRpt.Load(sReport)
        cView.Show()

    End Sub
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

13 Experts available now in Live!

Get 1:1 Help Now