问题描述
我有一个带有10个子报表的报表,我在主报表中有2个参数,并将子报表链接到这些参数.我的代码如下:
I have a REPORT WITH 10 SUBREPORTS, I have 2 Parameters in the main report and links the subreports to these parameters. my code looks like this:
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Configuration
Public Class CR
Public Sname As String
Public Dbname As String
Public Uname As String
Public Pwd As String
Public kid As Integer
Public oid As Integer
Private _passedText(180) As String
Public Property [PassedText]() As String()
Get
Return _passedText
End Get
Set(ByVal Value As String())
_passedText = Value
End Set
End Property
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 conn = New SqlClient.SqlConnection
conn = New SqlConnection(Form1.DS2)
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldLocation As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
'
' Get the report parameters collection.
'
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
conn.Open()
With crConnectionInfo
.ServerName = Sname
.DatabaseName = Dbname
.UserID = Uname
.Password = Pwd
End With
'
' Get the report parameters collection.
'
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
' Add a parameter value - START
crParameterFieldLocation = crParameterFieldDefinitions.Item("KundeID")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = kid
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
' Add a parameter value - END
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldLocation = crParameterFieldDefinitions.Item("OrdreID")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = oid
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
CrTables = cryRpt.Database.Tables
'
For Each CrTable In CrTables
Try
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Catch ex As Exception
MessageBox.Show("Reason for error:" & ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
Next
CrystalReportViewer1.ReportSource = cryRpt
conn.Close()
End Sub
我已经基于名为"kalkele1"的数据库制作了该报告,当我使用该报告运行该报告时,它的效果很好.但是我制作了一个该数据库的副本,并将其称为"kalkene2".当我以某种方式基于此报表运行报表时,我仅使用第一个参数将数据获取到子报表,而不使用参数2将其他数据获取到子报表.有人知道我在做什么错吗?
I have made the report based on a database called "kalkyle1" and when I run the report using this report it works great. But I made a copy of this database and called it "kalkyle2". When I run the report based on this report somehow I only gets the data to the subreports using the 1st parameter and not the others using parameter 2. anyone who has any idea what I am doing wrong?
推荐答案
这篇关于从数据库获取数据以生成报告的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!