last few days i m working with cryatal report 9 and vb.net 2003.
i found some usefull information for crystal report and vb.net. here are some
of that. i have to create a report with some sub report. The report is using
sql stored procedure in back-end. i have to pass it's parameter from vb.net.
there is one primary report and eleven sub report. this is a new experience for
me. i use stored procedure to calculate and retrive complex data from data
base. there was very good use of stored procedure. but finaly i have to work
with crystal report and vb.net for front-end.
'Finaly i create a class to show that report. this are the referance, in that class.
Imports System.Data.SqlClient Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared
Public Class rpt_Schema
Dim TheReport As Integer
Public Sub New(ByVal ReportIDX As Integer)
TheReport = ReportIDX
End Sub 'i create a function which returm all required informationform database for this report. and pass it in to parameter for crystal report. 'this fucntion return that report document.
Private Function generateReport() As
ReportDocument
Dim tmpCrystalReport As New ReportDocument tmpData = generateBasicInfo() tmpCrystalReport.Load(Application.StartupPath & "\Report\rptMain.rpt")
Dim crParameterDiscreteValue As ParameterDiscreteValue Dim crParameterFieldDefinitions As ParameterFieldDefinitions Dim crParameterFieldLocation As ParameterFieldDefinition Dim crParameterValues As ParameterValues
' Get the report's parameters collection. crParameterFieldDefinitions = tmpCrystalReport.DataDefinition.ParameterFields
'not i have to pass all parameters here. as follow: 'there was 36 parameters so i create this procedure "generateReport_child".
'param 1 generateReport_child("@vCenterIDX", tmpData.CenterIDX,crParameterFieldDefinitions, crParameterFieldLocation,crParameterValues)
'param 2 generateReport_child("@vYearIDX", tmpData.YearIDX, crParameterFieldDefinitions, crParameterFieldLocation, crParameterValues)
..... .....
'finaly
generateReport = tmpCrystalReport tmpCrystalReport = Nothing End Function
End Function
Private Sub generateReport_child( _ ByVal ParamName As String, _ ByVal ParamValue As Integer, _ ByVal crParameterFieldDefinitions As ParameterFieldDefinitions, _ ByVal crParameterFieldLocation As ParameterFieldDefinition, _ ByVal crParameterValues As ParameterValues)
'i have all arguments datatype was integer here Dim crParameterDiscreteValue As ParameterDiscreteValue crParameterFieldLocation = crParameterFieldDefinitions.Item(ParamName) crParameterValues = crParameterFieldLocation.CurrentValues crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue crParameterValues.Add(crParameterDiscreteValue) crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
End Sub
End Class
'----------------------------------- ''in form coding. just three line code.
Private Sub rptPreview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'create instance Dim rpt1 As New rpt_Schema(<>) CrystalReportViewer1.ReportSource = generateReport() rpt1 = Nothing
End Sub |
Crystal Decisions Project Examples
VB.NET Web Sample ApplicationsVB.NET Windows Sample Applicationsa ready code for sub report
click here.but i had a problem with, when i attach account report more then one time as sub
report in same primary report. i cant successfully pass parameters in that sub
report. if i will found any result for the same put that here letter.