Print Page | Close Window

Crystal reports 10

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=4015
Printed Date: 04 May 2025 at 8:24pm


Topic: Crystal reports 10
Posted By: justdotnetachar
Subject: Crystal reports 10
Date Posted: 18 Aug 2008 at 5:13am

I wanted to pass a parameter to stored procedure in crystal reports 10.I have one inculded subreports.without sub report it is working fine .But when we include a sub report (Mapped with Sp) with main report
then i am getting an error as Missing Parameter.please help me out . Thanks in advance

 

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Security.Principal
Imports System.Data
Imports System.Web
Partial Class Default3
    Inherits System.Web.UI.Page
    Dim crReportDocument As ReportDocument
    Dim crConnInfo As New ConnectionInfo
    Protected Sub CrystalReportViewer1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load

 

        crReportDocument = New ReportDocument()

 

        Dim rptFields As New ParameterFields()

        Dim paramStoreNo As New ParameterField()
        Dim discreteStoreNo As New ParameterDiscreteValue()

 

        Dim _db_server As String = "Spil232\Rolex"
        Dim _db_name As String = "Northwind"
        Dim _user_id As String = "Sprint"
        Dim _pwd As String = "Sprint"

 

        Dim oSubRpt 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 strReportPath As String

        strReportPath = "C:\Documents and Settings\vinod.bva\My Documents\Visual Studio 2005\WebSites\WebSite10\CrystalReport8.rpt"
        crReportDocument.Load(strReportPath)

 

        'log on to SQL server
        'Report code starts here
        'Set the database and the tables objects to the main report 'oRpt'
        crDatabase = crReportDocument.Database
        crTables = crDatabase.Tables
        'Loop through each table and set the connection info
        'Pess the connection info to the logoninfo object then apply the
        'logoninfo to the main report

        For Each crTable In crTables
            With crConnInfo
                .ServerName = _db_server
                .DatabaseName = _db_name
                .UserID = _user_id
                .Password = _pwd
                '.IntegratedSecurity = _iSecurity
            End With
            crLogOnInfo = crTable.LogOnInfo
            crLogOnInfo.ConnectionInfo = crConnInfo
            crTable.ApplyLogOnInfo(crLogOnInfo)
            If (crTable.TestConnectivity()) Then
                'drop fully qualified table location
                If (crTable.Location.IndexOf(".") > 0) Then
                    crTable.Location = crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)
                Else
                    crTable.Location = crTable.Location
                End If
            End If
            'crTable.LogOnInfo.ConnectionInfo.ServerName = crConnInfo.ServerName
        Next

        paramStoreNo.Name = "@regionId"
        paramStoreNo.ReportParameterType = ParameterType.ReportParameter
        paramStoreNo.ParameterValueType = ParameterValueKind.NumberParameter

        discreteStoreNo.Value = 1
        paramStoreNo.CurrentValues.Add(discreteStoreNo)
        rptFields.Add(paramStoreNo)


        'rptFields.Add(paramStoreNo)

        Dim s As String() = {"", ""}
        Dim index As Integer = 0


        CrystalReportViewer1.ReportSource = crReportDocument
        CrystalReportViewer1.ParameterFieldInfo = rptFields


        CrystalReportViewer1.DataBind()
        CrystalReportViewer1.Visible = True

    End Sub
End Class



-------------
vin



Replies:
Posted By: BrianBischof
Date Posted: 19 Aug 2008 at 1:17pm
In .NET 2005 (is that the version you're using?), there is now a SetParameterValue() method that you can use. It's much easier than coding each parameter like you are doing now (that is the .NET 2003 way). The SetParameterValue() method has an optional third argument which lets you specify the subreport name.
 
SetParameterValue(parameter name, value, subreport)
 
I have the .NET 2005/2008 book being posted online as I write it. I expect to have the printed version come out the first of November.  You can find out more about my books at http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com or reading the http://members.crystalreportsbook.com - Crystal Reports eBooks online.


-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>



Print Page | Close Window