SteveInBeloit
Well-known member
- Joined
- May 22, 2006
- Messages
- 132
- Programming Experience
- 10+
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
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
VB.NET:
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