不能在水晶报告中传递参数值

时间:2015-09-19 04:36:42

标签: crystal-reports

我有一个这样的代码,用于将参数字段值传递给crystal report。

Dim projectreportds As New ProjectRptnew -**this s dataset name**
        If ds.Tables.Count > 0 Then
            projectreportds.Tables(0).Merge(ds.Tables(0))
            Dim rpt As New ProjectReportNew-**this s report name**
            rpt.SetParameterValue("ExhbitionName", cmbExhibition.Text)
            Dim objrpt As New frmrptengine(AppPath & "\reports\ProjectReportNew.rpt", projectreportds)
            objrpt.ShowDialog()
        End If

但如果我正在运行此代码,则询问参数值。我必须在我的代码中进行哪些更改..

1 个答案:

答案 0 :(得分:0)

试试这个:

Set App = CreateObject("CrystalRuntime.Application")
report= "c:\report.rpt"
Set rep = app.OpenReport(report) 

For i = 1 To rpt.Database.Tables.Count
        Print rpt.Database.Tables(i).name
        If rpt.Database.Tables(i).name = "YOUR_TABLE_NAME" Then         
          //first table login
          rpt.Database.Tables(i).SetLogonInfo "YOUR_SERVER_NAME","YOUR_DATABASE_PATH",Username.Abbreviated,Password 
        Else
          //second table login
          rpt.Database.Tables(i).SetLogonInfo "YOUR_SERVER_NAME","YOUR_DATABASE_PATH",Username.Abbreviated,Password 
        End If
    Next    

YOUR_TABLE_NAME =表格的名称,您可以在“数据库”菜单,“数据库专家” - >“选定的表格”下找到它

YOUR_SERVER_NAME =源数据库的服务器名称

YOUR_DATABASE_PATH =源数据库的完整路径

Username.Abbreviated =访问数据库的用户名

密码=访问数据库“Username.Abbreviated”的密码

并传递参数字段:

rpt.ParameterFields(1).AddCurrentValue (num) 

num是我的参数字段

enter image description here