Subreport with formula selection
Hello,
I am using teo subreports in one report and main report is not using any table, but both subreports areusing one table for each. I have to retrieve data from subreports using a selection criteria, here it's schoolid.
After defining the formula field like {TmpForm7A.SchoolID}={@SchoolID} in Crystal reports, I have tried 'subRepDoc.DataDefinition.FormulaFields("SchoolID" ).Text = "'" & SchoolID & "'"
' in asp.net,but it's showing no record selection, eventhough there is value for the particular school id I passed into the program. When I tried to print 'FormulaName ', it was giving {@SchoolID}, but the folowing code is not functing I think. Any suggection?
subRepDoc.DataDefinition.FormulaFields("SchoolID") .Text = "'" & SchoolID & "'"
Thanks
Ceema
My code is as follows...
Dim Da As New SqlDataAdapter
Dim Ds As New DataSet
Dim Dai As New SqlDataAdapter
Dim Dsi As New DataSet
Dim SchoolID As String
Dim ClassID As String
SchoolID = "Ab1"
crDatabase = repDoc.Database
crTables = crDatabase.Tables
Dim myConnection As SqlConnection
For Each crTable In crTables
With crConnInfo
.ServerName = "IBRA"
.DatabaseName = "FSchool"
.UserID = "sa"
.Password = "123"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
If (crTable.TestConnectivity()) Then
If (crTable.Location.IndexOf(".") > 0) Then
crTable.Location = crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
Else
crTable.Location = crTable.Location
End If
Else
End If
Next
crSections = repDoc.ReportDefinition.Sections
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
crSubreportObject = CType(crReportObject, SubreportObject)
subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject. SubreportName)
crDatabase = subRepDoc.Database
crTables = crDatabase.Tables
For Each crTable In crTables
With crConnInfo
.ServerName = "IBRA"
.DatabaseName = "FSchool"
.UserID = "sa"
.Password = "123"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
Dim thisFormulaField As CrystalDecisions.CrystalReports.Engine.FormulaFiel dDefinition
Select Case crSubreportObject.SubreportName
Case "Form7DetailsB.rpt"
'********Tried to pass parameter value like this
'subRepDoc.DataDefinition.FormulaFields("SchoolID" ).Text = "'" & SchoolID & "'"
'tried to print number of formulas
'Response.Write(repDoc.DataDefinition.FormulaField s.Count)
For Each thisFormulaField In repDoc.DataDefinition.FormulaFields
' Response.Write(thisFormulaField.FormulaName)
If thisFormulaField.FormulaName = "{@SchoolID}" Then
subRepDoc.DataDefinition.FormulaFields("SchoolID") .Text = "'" & SchoolID & "'"
Response.Write(repDoc.DataDefinition.FormulaFields .Count)
End If
Next
Response.Write("<br>")
Case "Form7DetailsA.rpt"
For Each thisFormulaField In repDoc.DataDefinition.FormulaFields
If thisFormulaField.FormulaName = "{@SchoolID}" Then
subRepDoc.DataDefinition.FormulaFields("SchoolID") .Text = "'" & SchoolID & "'"
Response.Write(repDoc.DataDefinition.FormulaFields .Count)
End If
Next
End Select
Next
If (crTable.TestConnectivity()) Then
If (crTable.Location.IndexOf(".") > 0) Then
crTable.Location = crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
Else
crTable.Location = crTable.Location
End If
Else
End If
End If
Next
Next
CrystalReportViewer1.ReportSource = repDoc
End Sub
Function FunMyCon() As SqlConnection
Dim _ConStr As String
Dim _Conn As SqlConnection
_ConStr = ConfigurationSettings.AppSettings("MyDB")
_Conn = New SqlConnection(_ConStr)
_Conn.Open()
Return _Conn
End Function
|