crpe32.dll is version 13.0.5.891. This was developed in VS2012 and VB.NET. I'm using ADO.Net to connect to a MS SQL Server database. MainReport.SetDataSource(DTbl) bRC = PopulateAllSubReports(MainReport) If Not bRC Then Throw New Exception("Received an error in PopulateAllSubReports.") bRC = PopulateCrystalParameters(MainReport, SP) If Not bRC Then Throw New Exception("Received an error in PopulateCrystalParameters.") 'Actually create the output file. bRC = ExportData(MainReport) Private Function PopulateCrystalParameters(myReportDocument As ReportDocument, SP As ReportStoredProcedureCrystal) As Boolean Dim myParameterFieldDefinitions As ParameterFieldDefinitions = Nothing Dim myParameterFieldDefinition As ParameterFieldDefinition = Nothing, ParamValue As String = "" Dim bRC As Boolean, Param As SqlParameter = Nothing Try myParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields '*********************Report Parameters*************************** For Each myParameterFieldDefinition In myParameterFieldDefinitions myParameterFieldDefinition.CurrentValues.Clear() Select Case myParameterFieldDefinition.ParameterFieldName.Trim.ToUpper Case "@CARRIER" If SP.DBParameters.ContainsKey("@CARRIER") Then Param = SP.DBParameters("@CARRIER") ParamValue = NullS(Param.Value).Trim bRC = SetCurrentValueForParameterField(myParameterFieldDefinition, ParamValue) If Not bRC Then Return False End If End Select Next Return True Catch ex As Exception GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex) Return False End Try End Function Private Function SetCurrentValueForParameterField(myParameterFieldDefinition As ParameterFieldDefinition, submittedValue As Object) As Boolean Dim currentParameterValues As ParameterValues = Nothing Dim myParameterDiscreteValue As ParameterDiscreteValue = Nothing Try myParameterDiscreteValue = New ParameterDiscreteValue myParameterDiscreteValue.Value = NullS(submittedValue).Trim currentParameterValues = New ParameterValues currentParameterValues.Add(myParameterDiscreteValue) myParameterFieldDefinition.ApplyCurrentValues(currentParameterValues) Return True Catch ex As Exception GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex) Return False Finally myParameterDiscreteValue = Nothing currentParameterValues = Nothing End Try End Function Private Function SetDBSourceForSubReport(mySubReport As ReportDocument) As Boolean Dim myTables As Tables = Nothing, myTable As Table = Nothing, DTbl As DataTable, SP As StoredProcedure = Nothing Try myTables = mySubReport.Database.Tables For Each myTable In myTables Dim SPName As String = myTable.Location.Substring(0, myTable.Location.IndexOf(";"c)) SP = New StoredProcedure(ConnectionString, SPName, CommandType.StoredProcedure) DTbl = SP.FillTable mySubReport.SetDataSource(DTbl) SP = Nothing Next Return True Catch ex As Exception GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex) Return False Finally If Not SP Is Nothing Then SP = Nothing If Not myTable Is Nothing Then myTable = Nothing If Not myTables Is Nothing Then myTables = Nothing End Try End Function Private Function PopulateAllSubReports(myReportDocument As ReportDocument) As Boolean Try Dim mySections As Sections = myReportDocument.ReportDefinition.Sections For Each mySection As Section In mySections Dim myReportObjects As ReportObjects = mySection.ReportObjects For Each myReportObject As ReportObject In myReportObjects If myReportObject.Kind = ReportObjectKind.SubreportObject Then Dim mySubreportObject As SubreportObject = CType(myReportObject, SubreportObject) Dim subReportDocument As ReportDocument = mySubreportObject.OpenSubreport(mySubreportObject.SubreportName) Dim bRC = SetDBSourceForSubReport(subReportDocument) If Not bRC Then Return False End If Next Next Return True Catch ex As Exception GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex) Return False End Try End Function
↧
Re: Stored Procedure parameter (@Carrier) used in report and can't be set via code
↧