Search code examples
vb.netcrystal-reports

how to open crystal reports with folder in vb.net


Here is my Report load Function: But there is some problem. Report file in before bin folder then properly load. but i want to all reports separately in Report folder

Private Function GetDeliveryChallanPrint() As DataTable
    Dim data As New DataTable
    Using Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("VKDBx").ConnectionString)
        Using cmd As New SqlCommand("select * from DcMaster dm Left join DcDetail   dd  on dm.ID = dd.ID where dm.id = '" & PrinByIDTextBox.Text.ToString() & "'", Conn)
            Conn.Open()
            Using adp As New SqlDataAdapter
                adp.SelectCommand = cmd
                adp.Fill(data)

                Dim FILEPATH As String = Path.GetDirectoryName(Application.ExecutablePath + "\Reports")
                Dim DcPrint As New Rpt_DeliveryChallan
                DcPrint.Load(FILEPATH)
                DcPrint.SetDataSource(data)
                CrystalReportViewer1.ReportSource = DcPrint
                CrystalReportViewer1.Refresh()
                StatusLabel.Visible = False
                Conn.Close()
            End Using
        End Using
    End Using
End Function

Solution

  • You have two possibilities to load a Crystal Report on VB.NET:

    using the report object:

    Dim DcPrint As New Rpt_DeliveryChallan
    DcPrint.SetDataSource(data)
    CrystalReportViewer1.ReportSource = DcPrint
    CrystalReportViewer1.Refresh()
    

    Note: In this case you need to embed the report to the project.

    using the ReportDocument and load the report from file:

     Dim FILEPATH As String = CurDir() & "\Reports\Rpt_DeliveryChallan.rpt"
     Dim DcPrint As New ReportDocument
     DcPrint.Load(FILEPATH)
     DcPrint.SetDataSource(data)
     CrystalReportViewer1.ReportSource = DcPrint
     CrystalReportViewer1.Refresh()