首页 文章

来自Datagridview数据源的Crystal Report数据源

提问于
浏览
0

谁能帮我?我在VB.NET中有一个项目并试图向我的“CrystalReportViewer1”显示然后我从这个datagridview“MenuTambah.DGVTambah.DataSource”设置数据源 .

我在项目中创建“CrystalReport1.rpt”(项目>添加新项目> crystal report并将其命名为“CrystalReport1.rpt”)这是我的表单加载时的代码

Private Sub LaporanViewer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim crReportDocument As New CrystalReport1
    crReportDocument.SetDataSource(MenuTambah.DGVTambah.DataSource)
    CrystalReportViewer1.RefreshReport()
    'View the report 
    CrystalReportViewer1.ReportSource = crReportDocument
End Sub

我已经成功地在Datagridview中以名为“MenuTambah.DGVTambah”的其他形式加载了我的数据库表,然后我想基于我的datagridview使用上面的代码设置我的水晶文档数据源 . 当运行和“MenuTambah”加载时,没有异常错误或其他什么,只是退出,任何想法?

1 回答

  • 0

    试试这个

    点击 Project > Your Project Propertise > Settings
    enter image description here

    Public Sub ShowReport(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal filterstring As String, ByVal CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer) Dim myLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo Dim myTable As Table For Each myTable In MyReport.Database.Tables myLogonInfo = myTable.LogOnInfo myLogonInfo.ConnectionInfo.ServerName = My.Settings.RptserverPath.ToString myLogonInfo.ConnectionInfo.DatabaseName = My.Settings.Database.ToString myLogonInfo.ConnectionInfo.UserID = My.Settings.DBUser.ToString myLogonInfo.ConnectionInfo.Password = My.Settings.DBPass.ToString myTable.ApplyLogOnInfo(myLogonInfo) Next myTable CrystalReportViewer.ReportSource = MyReport CrystalReportViewer.SelectionFormula = filterstring CrystalReportViewer.Refresh() End Sub

    Private Sub SimpleButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton6.Click Dim MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument = New 'Your Report Name' ShowReport(MyReport, filterstring, CrystalReportViewer1) End Sub

相关问题