Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Crystal reports 10 Post Reply Post New Topic
Author Message
justdotnetachar
Newbie
Newbie


Joined: 18 Aug 2008
Location: India
Online Status: Offline
Posts: 7
Quote justdotnetachar Replybullet Topic: Crystal reports 10
    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
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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 Amazon.com or reading the 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>
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.