Results 1 to 2 of 2

Thread: [RESOLVED] VS 2005 Crystal reports help please

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    92

    Resolved [RESOLVED] VS 2005 Crystal reports help please

    HI!
    I am trying my first CR in VS 2005. I created the report with the wizard. When I hit Preview, I see the report with the data. I want to display it from my Form1. I have added the following code to the Form1 Load event. When I hit F5, it displays Form1, but it is blank. Not viewer or anything. Any idea what I am doing wrong?
    Thank You,
    Steve

    Code:
    Imports System
    Imports System.IO
    Imports System.Data.SqlClient
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
            Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
            Dim strConn As String = "User ID=sa;Password=sa;Initial Catalog=ForkLiftClientSQL;Data Source=CPServer;"
            CrystalReportViewer1.ActiveViewIndex = 0
            CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            CrystalReportViewer1.DisplayGroupTree = False
            CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
            CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
            CrystalReportViewer1.Name = "CrystalReportViewer1"
    
            Dim QueryString As String = "select * from tblTasks" 'Your Query here
            Dim Connection As New SqlConnection(strConn) 'Your Database Connection Here
            Try
                Connection.Open()
                Dim Adapter As SqlDataAdapter = New SqlDataAdapter(QueryString, Connection) 'Passing the query in the connection
                Dim DataSet As DataSet = New DataSet() 'DataSet
                Adapter.Fill(DataSet)
    
                Dim DataTable As DataTable = New DataTable 'DataTable 
    
                DataTable = DataSet.Tables(0) 'filling the datatable here 
                'Report.Load(Application.StartupPath & "/Report/" & "/CrystalReport1.rpt") 'Report Name Here
                Report.Load("..\..\CrystalReport1.rpt") 'Report Name Here
                Report.SetDataSource(DataTable)
                CrystalReportViewer1.ReportSource = Report
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Bad Deal", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
    End Class
    VS 2005 .net, SQL Server

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    92

    Re: VS 2005 Crystal reports help please

    Solved!

    Had to add the control to the parent container.

    Form1.Controls.Add CrystalReportViewer1
    VS 2005 .net, SQL Server

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width