Link to home
Start Free TrialLog in
Avatar of majeeka
majeeka

asked on

crystal reports vb.net

Hi,

i'm creating a VB.net project. in the project i use datasets and VB adapters and now i would like to use crystal reports to display these datasets as charts. currently i can display the datasets in a datagrid and when i run the project this works fine.
i've created a report using the crystal reports wizard.  

In the wizard I set one of the datasets as the source of information.  On the form I have inserted a crystal report viewer and set the data source to be the report.

 However when I now run the project, I get a database logon request.  I don't know why it would ask me for this as I don't need to connect supply this information when I'm returning the dataset to the datagrid.  I have checked all the fields and they match up correctly with the naming in the database.


I've pasted the report code below.

Thanks in advance to anyone who can help me out here!!!!! I'm going crazy!


Majeeka




Option Strict Off
Option Explicit On

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Shared
Imports System
Imports System.ComponentModel


Public Class CrystalReport1
    Inherits ReportClass
   
    Public Sub New()
        MyBase.New
    End Sub
   
    Public Overrides Property ResourceName As String
        Get
            Return "CrystalReport1.rpt"
        End Get
        Set
            'Do nothing
        End Set
    End Property
   
    <Browsable(false),  _
     DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)>  _
    Public ReadOnly Property Section1 As CrystalDecisions.CrystalReports.Engine.Section
        Get
            Return Me.ReportDefinition.Sections(0)
        End Get
    End Property
   
    <Browsable(false),  _
     DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)>  _
    Public ReadOnly Property Section2 As CrystalDecisions.CrystalReports.Engine.Section
        Get
            Return Me.ReportDefinition.Sections(1)
        End Get
    End Property
   
    <Browsable(false),  _
     DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)>  _
    Public ReadOnly Property Section3 As CrystalDecisions.CrystalReports.Engine.Section
        Get
            Return Me.ReportDefinition.Sections(2)
        End Get
    End Property
   
    <Browsable(false),  _
     DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)>  _
    Public ReadOnly Property Section4 As CrystalDecisions.CrystalReports.Engine.Section
        Get
            Return Me.ReportDefinition.Sections(3)
        End Get
    End Property
   
    <Browsable(false),  _
     DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Hidden)>  _
    Public ReadOnly Property Section5 As CrystalDecisions.CrystalReports.Engine.Section
        Get
            Return Me.ReportDefinition.Sections(4)
        End Get
    End Property
End Class

<System.Drawing.ToolboxBitmapAttribute(GetType(CrystalDecisions.Shared.ExportOptions), "report.bmp")>  _
Public Class CachedCrystalReport1
    Inherits Component
    Implements ICachedReport
   
    Public Sub New()
        MyBase.New
    End Sub
   
    Public Overridable Property IsCacheable As Boolean Implements CrystalDecisions.ReportSource.ICachedReport.IsCacheable
        Get
            Return true
        End Get
        Set
            '
        End Set
    End Property
   
    Public Overridable Property ShareDBLogonInfo As Boolean Implements CrystalDecisions.ReportSource.ICachedReport.ShareDBLogonInfo
        Get
            Return false
        End Get
        Set
            '
        End Set
    End Property
   
    Public Overridable Property CacheTimeOut As System.TimeSpan Implements CrystalDecisions.ReportSource.ICachedReport.CacheTimeOut
        Get
            Return CachedReportConstants.DEFAULT_TIMEOUT
        End Get
        Set
            '
        End Set
    End Property
   
    Public Overridable Function CreateReport() As CrystalDecisions.CrystalReports.Engine.ReportDocument Implements CrystalDecisions.ReportSource.ICachedReport.CreateReport
        Dim rpt As CrystalReport1 = New CrystalReport1
        rpt.Site = Me.Site
        Return rpt
    End Function
   
    Public Overridable Function GetCustomizedCacheKey(ByVal request As RequestContext) As String Implements CrystalDecisions.ReportSource.ICachedReport.GetCustomizedCacheKey
        Dim key As [String] = Nothing
        '// The following is the code used to generate the default
        '// cache key for caching report jobs in the ASP.NET Cache.
        '// Feel free to modify this code to suit your needs.
        '// Returning key == null causes the default cache key to
        '// be generated.
        '
        'key = RequestContext.BuildCompleteCacheKey(
        '    request,
        '    null,       // sReportFilename
        '    this.GetType(),
        '    this.ShareDBLogonInfo );
        Return key
    End Function
End Class


Avatar of Sourabhm
Sourabhm
Flag of United Kingdom of Great Britain and Northern Ireland image

majeeka,

Use the following code to display crystal report.

Dim ss As New CrystalReport1

        Dim dSet As New DataSet

        Dim oleConn As New OleDbConnection("<Connection String>")

        Dim oleAdapter As New OleDbDataAdapter
        oleAdapter.SelectCommand = New OleDbCommand("<SQL String>", oleConn)
        oleAdapter.Fill(dSet, "<Table Name specified in SQL String>")

        ss.Database.Tables(0).SetDataSource(dSet)
   
        CrystalReportViewer1.ReportSource = ss

Avatar of majeeka
majeeka

ASKER

Thanks,

Sorry i'm having trouble understanding exactly where to put this? I pasted it into the form but it is giving errors regarding the oledbConnection not defined and the same error for the oledbdataAdapter?

I'm sorry for not getting this, i've pasted the form below and if you could take a look and and instruct me on where to insert the code, i'd greatly appreciate it.

Thanks,

majeeka.



Public Class Stock
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
    Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
    Friend WithEvents DsStockTake1 As fyp.dsStockTake
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.DsStockTake1 = New fyp.dsStockTake
        Me.Button2 = New System.Windows.Forms.Button
        Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
        Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
        Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
        Me.Button3 = New System.Windows.Forms.Button
        Me.CrystalReportViewer1 = New CrystalDecisions.Windows.Forms.CrystalReportViewer
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DsStockTake1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.Top
        Me.Label1.Font = New System.Drawing.Font("Verdana", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(264, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(392, 24)
        Me.Label1.TabIndex = 7
        Me.Label1.Text = "Stock-Take"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(704, 584)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(144, 23)
        Me.Button1.TabIndex = 8
        Me.Button1.Text = "Update Database"
        '
        'DataGrid1
        '
        Me.DataGrid1.DataMember = "Product"
        Me.DataGrid1.DataSource = Me.DsStockTake1
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(40, 152)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(800, 200)
        Me.DataGrid1.TabIndex = 9
        '
        'DsStockTake1
        '
        Me.DsStockTake1.DataSetName = "dsStockTake"
        Me.DsStockTake1.EnforceConstraints = False
        Me.DsStockTake1.Locale = New System.Globalization.CultureInfo("en-IE")
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(48, 120)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(112, 24)
        Me.Button2.TabIndex = 10
        Me.Button2.Text = "Launch StockTake"
        '
        'OleDbDataAdapter1
        '
        Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
        Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Product", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ProductId", "ProductId"), New System.Data.Common.DataColumnMapping("prodId", "prodId"), New System.Data.Common.DataColumnMapping("stockTakeId", "stockTakeId"), New System.Data.Common.DataColumnMapping("ProductName", "ProductName"), New System.Data.Common.DataColumnMapping("actualStockLevel", "actualStockLevel"), New System.Data.Common.DataColumnMapping("finalCount", "finalCount"), New System.Data.Common.DataColumnMapping("differenceReason", "differenceReason"), New System.Data.Common.DataColumnMapping("stockCategory", "stockCategory")})})
        '
        'OleDbSelectCommand1
        '
        Me.OleDbSelectCommand1.CommandText = "SELECT ProductId, ProductName FROM Product"
        Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Integrated Security=SSPI;Packet Size=4096;Data Source=Katie;Tag with column colla" & _
        "tion when possible=False;Initial Catalog=master;Use Procedure for Prepare=1;Auto" & _
        " Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID" & _
        "=KATIE;Use Encryption for Data=False"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(264, 120)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 11
        Me.Button3.Text = "test reading"
        '
        'CrystalReportViewer1
        '
        Me.CrystalReportViewer1.ActiveViewIndex = -1
        Me.CrystalReportViewer1.Location = New System.Drawing.Point(224, 448)
        Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
        Me.CrystalReportViewer1.ReportSource = "C:\Documents and Settings\Katie Murphy\Desktop\FYP\BAR_VERSION3.1\CrystalReport1." & _
        "rpt"
        Me.CrystalReportViewer1.Size = New System.Drawing.Size(424, 176)
        Me.CrystalReportViewer1.TabIndex = 12
        '
        'Stock
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(992, 666)
        Me.Controls.Add(Me.CrystalReportViewer1)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.DataGrid1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Stock"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Stock"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DsStockTake1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = DialogResult.OK
    End Sub

    Private Sub Stock_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DsStockTake1.Clear()
        OleDbDataAdapter1.Fill(DsStockTake1)

        DsStockTake1.WriteXml("C:\Documents and Settings\Katie Murphy\My Documents\Pocket_PC1 My Documents\sync.xml")
    End Sub

    Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim frmHelpDialog As New reading
        frmHelpDialog.ShowDialog()
    End Sub

End Class

ASKER CERTIFIED SOLUTION
Avatar of Sourabhm
Sourabhm
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of majeeka

ASKER

Thats brilliant thanks!!!!!!