Crystal Report Data source from Datagridview datasource

不羁的心 提交于 2020-01-07 03:07:30

问题


Can anyone help me? I have a project in VB.NET and trying to show to my "CrystalReportViewer1" then I set datasource from this datagridview "MenuTambah.DGVTambah.DataSource".

I create "CrystalReport1.rpt" in project (project > add new item> crystal report and named it "CrystalReport1.rpt") this is the code when my form load

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

I have successfully loaded my database table in that Datagridview in other form called "MenuTambah.DGVTambah" then I want to set my crystal document datasource based on my datagridview with code above. When run and when "MenuTambah" load, there is no exception error or something, just exit, any idea?


回答1:


Try this

Click on: Project > Your Project Propertise > Settings

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


来源:https://stackoverflow.com/questions/33974747/crystal-report-data-source-from-datagridview-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!