locked
Connecting a stored procedure to a crystal report RRS feed

  • Question

  • User-1582039473 posted

    Split off from http://forums.asp.net/t/1146626.aspx/2/10?Connecting+a+stored+procedure+to+a+crystal+report

    This code is work...

    but when i call same code on button click its ask twice parameter value...

    Then after report will disply..

    This is my code...

    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Imports System.Data
    Imports System.Data.SqlClient
    
    Partial Class Default3
        Inherits System.Web.UI.Page
    
        Private Sub ConfigureReport()
            If Not Page.IsPostBack Then
                Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
                myConnectionInfo.DatabaseName = "HDFC"
                myConnectionInfo.UserID = "sa"
                myConnectionInfo.Password = "sa@123"
                Dim ReportPath As String = Server.MapPath("CrystalReport2.rpt")
                ReportViewer1.ReportSource = ReportPath
    
    
                Dim field1 As ParameterField = Me.ReportViewer1.ParameterFieldInfo(0)
    
                Dim val1 As New ParameterDiscreteValue()
    
                val1.Value = "TKTNO"
    
                field1.CurrentValues.Add(val1)
    
                SetDBLogonForReport(myConnectionInfo)
            End If
        End Sub
    
        Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo)
            Dim myTableLogOnInfos As TableLogOnInfos = ReportViewer1.LogOnInfo()
            For Each myTableLogOnInfo As TableLogOnInfo In myTableLogOnInfos
                myTableLogOnInfo.ConnectionInfo = myConnectionInfo
            Next
        End Sub
    
    
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
            myConnectionInfo.DatabaseName = "HDFC"
            myConnectionInfo.UserID = "sa"
            myConnectionInfo.Password = "sa@123"
            Dim ReportPath As String = Server.MapPath("CrystalReport3.rpt")
            ReportViewer1.ReportSource = ReportPath
    
    
    
            Dim field1 As ParameterField = Me.ReportViewer1.ParameterFieldInfo(0)
    
            Dim val1 As New ParameterDiscreteValue()
    
            val1.Value = "TKTNO"
    
            field1.CurrentValues.Add(val1)
    
            SetDBLogonForReport(myConnectionInfo)
    
    
        End Sub
    End Class
    
    
    
    
    .aspx code...
    
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" %>
    
    <%@ Register assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <CR:CrystalReportViewer ID="ReportViewer1" runat="server" AutoDataBind="true" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
        </div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        </form>
    </body>
    </html>



    Tuesday, July 10, 2012 3:25 AM

All replies

  • User155121074 posted

    Hello Jayshree,

     Please check parameter name in your crystal report and in code. Make sure that both are same.

    Count parameter from crystal report.

    Tuesday, July 10, 2012 9:52 AM