如何设置来自 app.config 的 crystal 报告数据源
How can I set crystal report datasource from app.config
如何从 app.config 设置 crystal 报告数据源?
我认为这将帮助我在没有开发人员帮助的情况下将应用程序移动到不同的服务器。我已经尝试连接数据集。
数据库:'Integrity security=True'
我想获取按订单号过滤的报告
为此,我在数据集中创建了一个数据表 'Order details'(带有内部连接查询)并将其与 crystal 报表连接,并使用记录选择公式来过滤 'OrderNo',但是虽然它加载运行时,显示数据库登录屏幕以输入数据库登录 ID、密码等。
有人可以帮助解决问题或建议任何其他方法吗?
按照我目前的方法,这会占用太多加载时间吗?或者我可以使用 'parameterized Datatable adapter' 吗?如果是的话怎么办?
争议很多..
加载代码:
Dim cryRpt As New ReportDocument
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim path As String = ""
Dim READER As SqlDataReader
Dim path As String = "C:\Users\MYPC\Documents\Visual Studio 2010\Projects\Laundry MasterLap\Laundry Master\Reports\reportOrderPrint.rpt"
cryRpt.Load(path)
cryRpt.SetParameterValue(0, OrderNo)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
crystal 报告无法直接从 app.config 获取凭据。您需要传递 ConnectionInfo class 以将数据库凭据传递给 crystal 报告
导入以下名称space
Imports CrystalDecisions.CrystalReports.Engine
import CrystalDecisions.Shared
在你的函数中
Dim Logoninfos As new TableLogOnInfos
Dim Logoninfo As new TableLogOnInfo
Dim conInfo As new ConnectionInfo
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim cryRpt As New ReportDocument
Dim path As String = "C:\Users\MYPC\Documents\Visual Studio 2010\Projects\Laundry MasterLap\Laundry Master\Reports\reportOrderPrint.rpt"
cryRpt.Load(path)
将数据库名称、服务器名称等放在这里
conInfo.ServerName = "SERVER NAME";
conInfo.DatabaseName = "DATABASE NAME";
conInfo.UserID = "USERNAME";
conInfo.Password = "PASSWORD";
将其分配给数据源中的每个 table
for each CrTable in cryRpt.Database.Tables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
next
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
如何从 app.config 设置 crystal 报告数据源? 我认为这将帮助我在没有开发人员帮助的情况下将应用程序移动到不同的服务器。我已经尝试连接数据集。
数据库:'Integrity security=True'
我想获取按订单号过滤的报告
为此,我在数据集中创建了一个数据表 'Order details'(带有内部连接查询)并将其与 crystal 报表连接,并使用记录选择公式来过滤 'OrderNo',但是虽然它加载运行时,显示数据库登录屏幕以输入数据库登录 ID、密码等。
有人可以帮助解决问题或建议任何其他方法吗? 按照我目前的方法,这会占用太多加载时间吗?或者我可以使用 'parameterized Datatable adapter' 吗?如果是的话怎么办?
争议很多..
加载代码:
Dim cryRpt As New ReportDocument
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim path As String = ""
Dim READER As SqlDataReader
Dim path As String = "C:\Users\MYPC\Documents\Visual Studio 2010\Projects\Laundry MasterLap\Laundry Master\Reports\reportOrderPrint.rpt"
cryRpt.Load(path)
cryRpt.SetParameterValue(0, OrderNo)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
crystal 报告无法直接从 app.config 获取凭据。您需要传递 ConnectionInfo class 以将数据库凭据传递给 crystal 报告
导入以下名称space
Imports CrystalDecisions.CrystalReports.Engine
import CrystalDecisions.Shared
在你的函数中
Dim Logoninfos As new TableLogOnInfos
Dim Logoninfo As new TableLogOnInfo
Dim conInfo As new ConnectionInfo
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
Dim cryRpt As New ReportDocument
Dim path As String = "C:\Users\MYPC\Documents\Visual Studio 2010\Projects\Laundry MasterLap\Laundry Master\Reports\reportOrderPrint.rpt"
cryRpt.Load(path)
将数据库名称、服务器名称等放在这里
conInfo.ServerName = "SERVER NAME";
conInfo.DatabaseName = "DATABASE NAME";
conInfo.UserID = "USERNAME";
conInfo.Password = "PASSWORD";
将其分配给数据源中的每个 table
for each CrTable in cryRpt.Database.Tables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
next
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()