Solved

How to use Crystal Reports in VB.NET

Posted on 2006-07-13
1
349 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

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

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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

20 Experts available now in Live!

Get 1:1 Help Now