如何从app.config

时间:2015-06-26 05:46:29

标签: vb.net crystal-reports crystal-reports-2010

如何从app.config设置水晶报表数据源? 我认为哪些可以帮助我在没有开发人员帮助的情况下将应用程序移动到不同的服务器。我已尝试尝试连接数据集。

数据库:'诚信安全=真'

我想按照订单编号过滤报告

为此我在数据集中创建了一个数据表'Order details'(带有内连接查询)并将其与crystal report连接,并使用记录选择公式来过滤'OrderNo',但是当它加载运行时,显示数据库登录屏幕到输入数据库登录ID,密码等

有人可以帮助解决问题或建议任何其他方法吗? 按照我目前的方法,这会占用太多的加载时间吗?或者我可以使用'参数化数据表适配器'吗?如果是的话怎么样?

Sawmany纠纷..

加载代码:

   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()

1 个答案:

答案 0 :(得分:0)

水晶报告无法直接从app.config获取凭据。您需要传递ConnectionInfo类以将数据库凭据传递给crystal report

导入以下名称空间

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";

将其分配给数据源中的每个表

for each  CrTable in cryRpt.Database.Tables
    crtableLogoninfo = CrTable.LogOnInfo
    crtableLogoninfo.ConnectionInfo = crConnectionInfo
    CrTable.ApplyLogOnInfo(crtableLogoninfo)
next

CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()