来自Datagridview数据源的Crystal Report数据源 [英] Crystal Report Data source from Datagridview datasource
问题描述
有人可以帮助我吗?我在VB.NET中有一个项目,尝试显示给我的 CrystalReportViewer1,然后从该datagridview MenuTambah.DGVTambah.DataSource中设置数据源。
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".
我创建了项目中的 CrystalReport1.rpt(项目>添加新项> Crystal Report并将其命名为 CrystalReport1.rpt)
这是我的表单加载时的代码
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
我已经成功以另一种名为 MenuTambah.DGVTambah的形式在Datagridview中加载了数据库表,然后我想使用上述代码基于我的datagridview设置Crystal文档数据源。当运行并加载 MenuTambah时,没有异常错误或什么,只是退出,有任何想法吗?
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?
推荐答案
尝试一下
单击:项目>项目属性>设置
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
这篇关于来自Datagridview数据源的Crystal Report数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!