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

时间:2015-11-28 18:16:49

标签: vb.net crystal-reports

任何人都可以帮助我吗?我在VB.NET中有一个项目并试图向我的“CrystalReportViewer1”显示然后我从这个datagridview“MenuTambah.DGVTambah.DataSource”设置数据源。

我在项目中创建“CrystalReport1.rpt”(项目>添加新项目>水晶报告并将其命名为“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 :(得分:0)

试试这个

点击项目> 您的项目属性> 设置 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