水晶报表vb.net的问题 [英] Issue with crystal report vb.net
问题描述
我用子报表制作了水晶报表,
在子报表中,我添加了以下命令:
I have made a crystal report with subreports,
In my subreports I have added commands like:
SELECT * FROM Orders where orederID = {?orderID}
当我在查看器中运行报表时,报表会提示带有对话框的orderID.
但是我有几个子报表,它们要求使用相同的orderID来提示每个子报表的值.
When I run the report in viewer the report prompts for the orderID with a dialogbox.
But I have several subreports that requires the same orderID it prompt for the value for every subreport. Is there a way to make the report get the ordreID once and reuse it for each subreport without the need for the prompt, ogr is it a way to do it in code?
推荐答案
我做了 DuckDuckGo [如何将子报表链接到主报表水晶报表 [ ^ ].
I did a DuckDuckGo[^] search and here is a result that might be useful How to link Sub Report to Main Crystal Report [^].
感谢您解决了问题1,现在该报告适用于本地数据库,
下一个问题是,我还需要能够连接到远程数据库以进行报告,或者仅能够连接到其他数据库.
我在互联网上搜索了有关此问题的帮助,并找到了一些我尝试过的代码片段.代码看起来像这样.
Thank you that solved issue number 1, now the report works with the local database,
The next issue is that I need to be able to connect to a remote database as well to make a report or just to be able to connect to a different database.
I have searched the internet for help on this issue, and found some code-snips that I have tried out. the code looks like this.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Configuration
Public Class CR
Private Sub CR_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cryRpt As New ReportDocument
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table
cryRpt.Load("Reports/CrystalReport5.rpt")
'***************************************************************
Dim Sname As String
Dim Dbname As String
Dim Uname As String
Dim Pwd As String
Dim kid As Integer = 1
Dim oid As Integer = 1
Sname = CRdb.Servadr
Dbname = CRdb.Servname
Uname = CRdb.Username
Pwd = CRdb.Passw
MsgBox("Sname = " & Sname)
MsgBox("Dbname = " & Dbname)
MsgBox("Uname = " & Uname)
MsgBox("Pwd = " & Pwd)
'****************************************************************
With crConnectionInfo
.ServerName = "JOHNMOLANDS-PC\SQLEXPRESS"
.DatabaseName = "Kalkyle1"
.UserID = "User2"
.Password = "user2"
End With
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
' Begin parameter
crParameterFieldDefinition = crParameterFieldDefinitions.Item("KundeID")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = kid
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
' End parameter
Dim crParameterFieldDefinitions2 As ParameterFieldDefinitions
Dim crParameterFieldDefinition2 As ParameterFieldDefinition
Dim crParameterValues2 As ParameterValues
Dim crParameterDiscreteValue2 As ParameterDiscreteValue
crParameterFieldDefinitions2 = cryRpt.DataDefinition.ParameterFields
' Begin parameter
crParameterFieldDefinition2 = crParameterFieldDefinitions2.Item("OrdreID")
crParameterValues2 = crParameterFieldDefinition2.CurrentValues
crParameterDiscreteValue2 = New ParameterDiscreteValue
crParameterDiscreteValue2.Value = oid
crParameterValues2.Add(crParameterDiscreteValue2)
crParameterFieldDefinition2.ApplyCurrentValues(crParameterValues2)
' End parameter
CrTables = cryRpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
CrystalReportViewer1.ReportSource = cryRpt
End Sub
End Class
但是,当我运行此代码时,报告一遍又一遍地询问所有子报表的第一个参数,但从未询问第二个参数,最后,当报告加载时,缺少链接到第二个参数的所有数据. br/>
这是为什么?我没有收到任何登录信息的提示,所以我猜那部分仍在工作,但是在某些地方出了问题,参数链接不起作用.
But when I run this code, the report asks for the first parameter over and over and over again for all subreports but never for the second parameter, then in the end when the report loads all the data linked to the second parameter is missing.
Why is that? I do not get promted for any logon info so I guess that part is working but somewhere along the way something goes wrong and the parameter links does not work.
这篇关于水晶报表vb.net的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!