0
votes

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
Or anyone know the best way to select a dataset then make it as a source for my crystaldocument?Bondan's Blackk Diamond

1 Answers

0
votes

Try this

Click on: Project > Your Project Propertise > Settings

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