如何使用 vb.net 中的文件夹打开 crystal 报告

how to open crystal reports with folder in vb.net

这是我的报告加载函数:但是有一些问题。 bin 文件夹之前的报告文件然后正确加载。但我想在 Report 文件夹

中单独显示所有报告
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

您有两种方法可以在 VB.NET 上加载 Crystal 报告:

使用报告对象:

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

注意:在这种情况下,您需要将报表嵌入到项目中。

使用 ReportDocument 并从文件加载报告:

 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()