|
-
Sep 29th, 2003, 11:03 PM
#1
Thread Starter
Hyperactive Member
Crystalreport-StoredProcedure
hi
How to Use Stored Procedure and how can i pass the parameter values through vb.net
i am not using original verion of Crystlreport. i am using Crystalreport which is
available in Vs.net Studio.
I need to be chage the Date Criteria. How to accomplish this.
Please help me.
-
Sep 30th, 2003, 11:10 AM
#2
Lively Member
First, some support functions:
Private Sub SetLogonInfo()
Dim subRepDoc As New ReportDocument
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crLogOnInfo As TableLogOnInfo
Dim crConnInfo As New ConnectionInfo
Try
crDatabase = report.Database
crTables = crDatabase.Tables
'Loop through each table and set the connection info
'Pass the connection info to the logoninfo object then apply the
'logoninfo to the main report
For Each crTable In crTables
With crConnInfo
.ServerName = AppSettings(AppSettings("ENVIRONMENT") & "DATABASE_SERVER")
.DatabaseName = AppSettings("DATABASE_NAME")
.UserID = AppSettings("DATABASE_USERNAME")
.Password = AppSettings("DATABASE_PASSWORD")
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
Next
'Set the sections collection with report sections
crSections = report.ReportDefinition.Sections
'Loop through each section and find all the report objects
'Loop through all the report objects to find all subreport objects, then set the
'logoninfo to the subreport
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
'If you find a subreport, typecast the reportobject to a subreport object
crSubreportObject = CType(crReportObject, SubreportObject)
'Open the subreport
subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
crDatabase = subRepDoc.Database
crTables = crDatabase.Tables
'Loop through each table and set the connection info
'Pass the connection info to the logoninfo object then apply the
'logoninfo to the subreport
For Each crTable In crTables
With crConnInfo
.ServerName = AppSettings(AppSettings("ENVIRONMENT") & "DATABASE_SERVER")
.DatabaseName = AppSettings("DATABASE_NAME")
.UserID = AppSettings("DATABASE_USERNAME")
.Password = AppSettings("DATABASE_PASSWORD")
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
Next
End If
Next
Next
Catch ex As Exception
Throw New Exception("Error in SetLogonInfo", ex)
End Try
End Sub
Now my form load event
Private Sub frmCRViewer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Try
Select Case ReportType
Case "JobSheet"
report = New rptJobSheet
Me.Text = "Job overview report"
'Set jobID value
crParameterDiscreteValue.Value = JobID
'Access first parameter field definition
crParameterFieldDefinitions = report.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("JobID")
' Add parameter value
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
' Apply the current value to the parameter definition
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
Case "InterpreterDetails"
report = New rptInterpreterDetails
Me.Text = "Interpreter detail report"
'Set intID value
crParameterDiscreteValue.Value = IntID
'Access first parameter field definition
crParameterFieldDefinitions = report.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("IntID")
' Add parameter value
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
' Apply the current value to the parameter definition
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
Case "Master job summary"
Me.Text = "Master job summary"
report = New rptMasterJob
'Set jobID value
crParameterDiscreteValue.Value = JobID
'Access first parameter field definition
crParameterFieldDefinitions = report.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("JobID")
' Add parameter value
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
' Apply the current value to the parameter definition
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
Case Else
Throw New Exception("Unknown report format! ReportType: " & ReportType)
End Select
SetLogonInfo()
crViewer.ReportSource = report
crViewer.Show()
Catch ex As Exception
Throw New Exception("Error in frmCRViewer_Load", ex)
Finally
Me.Cursor = System.Windows.Forms.Cursors.Default
End Try
End Sub
and here is how i create my viewer form:
Dim frmCRV As New frmCRViewer("Master job summary", Me)
frmcrv.JobID = aJob.JobID
frmCRV.ShowDialog()
frmCRV = Nothing
My viewer form has the following variables defined
Private report As ReportDocument
Private ReportType As String
Public MainForm As frmMain ' reference to my main form
Public JobID As Integer = 0
Public IntID As Integer = 0
constructor looks like this:
Public Sub New(ByVal report As String, ByVal form As frmMain)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
ReportType = report
MainForm = form
End Sub
Start using that SetLogon sub now. it will save you time.
AppSettings is out of the System.Configuration.ConfigurationSettings namespace. I have an app.config file that has the keys in it as shown in the code. This is required if you want to use the code as is.
Let me know if you need anything else
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|