Crystal report with Asp.net - newbie

Last post 05-11-2008 8:10 AM by bvaland80. 1 replies.

Sort Posts:

  • Crystal report with Asp.net - newbie

    05-10-2008, 8:53 PM
    • Loading...
    • bvaland80
    • Joined on 03-04-2008, 10:50 AM
    • Posts 16

    Hi All

    I'm newbie to crystal reports, i would like to run crystal report on the web form asp.net.

    I have created a new crystal report file as reconrpt.rpt, i was to load the report on the webform.

    The report make use of a stored procedure and with two parameter which i would like user pass that from webform and onsubmit button it pass that fields.

    After few hours of research on internet i managed to write small to load the report and parameter. The report request for database login and then it goes blank once enter credential and click logon.

     

            Dim rpt As ReportDocument
            rpt = New ReportDocument
            CrystalReportViewer1.DataBind()
            rpt.Load(Server.MapPath("reconrpt.rpt"), CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
            rpt.SetDatabaseLogon("xuser", "xpassword", "localhost", "northwind")
    
            rpt.SetParameterValue("@sbatch", "1")
            rpt.SetParameterValue("@ebatch", "10")
    
    
            CrystalReportViewer1.ReportSource = rpt
            CrystalReportViewer1.ShowFirstPage()
    
    
     
  • Re: Crystal report with Asp.net - newbie

    05-11-2008, 8:10 AM
    • Loading...
    • bvaland80
    • Joined on 03-04-2008, 10:50 AM
    • Posts 16

    Further research, i have managed to get all working, below is the code that might help someone

      

        Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                trcryrep.Style.Remove("display")
                Session("Rep") = Nothing
                BindReport()
                Me.CrystalReportViewer1.ShowFirstPage()
            Catch ex As Exception
                ErrMsg.Text = ex.Message()
            End Try
        End Sub
    
        Private Sub BindReport()
    
            If Session("Rep") Is Nothing Then
    
                Dim ConnInfo As New ConnectionInfo
                With ConnInfo
                    .ServerName = "xx"
                    .DatabaseName = "xx"
                    .UserID = "xx"
                    .Password = "xx"
                End With
    
                Dim rep As New ReportDocument
                rep.Load(Server.MapPath("reconrpt.rpt"))
                Me.CrystalReportViewer1.ReportSource = rep
                Dim RepTbls As Tables = rep.Database.Tables
                For Each RepTbl As Table In RepTbls
                    Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo
                    RepTblLogonInfo.ConnectionInfo = ConnInfo
                    RepTbl.ApplyLogOnInfo(RepTblLogonInfo)
                Next
    
                Dim xbatchfrom As Integer = 0
                Dim xbatchto As Integer = 0
    
                If batchfrom.Text.Trim() <> "" Then
                    xbatchfrom = Convert.ToInt32(batchfrom.Text.Trim())
                End If
    
                If batchto.Text.Trim() <> "" Then
                    xbatchto = Convert.ToInt32(batchto.Text.Trim())
                End If
    
                rep.SetParameterValue("@sbatch", xbatchfrom)
                rep.SetParameterValue("@ebatch", xbatchto)
    
                Session("Rep") = rep
    
            End If
    
            Me.CrystalReportViewer1.ReportSource = Session("Rep")
            Me.CrystalReportViewer1.DataBind()
    
        End Sub
    
        Protected Sub CrystalReportViewer1_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Init
            BindReport()
        End Sub
     
Page 1 of 1 (2 items)