Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
My web page is blank the data are not displayed in my report here is the code:
The exported file is there but why the report is not displayed in the web page???

VB
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration


Public Class WebForm3
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim rptDoc As ReportDocument = New ReportDocument
        Dim ds As DataSet1 = New DataSet1
        Dim dt As DataTable = New DataTable
        ' Just set the name of data table
        dt.TableName = "Crystal Report Example"
        dt = getAllOrders
        'This function is located below this function
        ds.Tables(0).Merge(dt)
        ' Your .rpt file path will be below
        rptDoc.Load(Server.MapPath("CrystalReport4.rpt"))
        'set dataset to the report viewer.
        rptDoc.SetDataSource(ds)
        rptDoc.ExportToDisk(ExportFormatType.Excel, Server.MapPath("myExcelFile.xls"))
        CrystalReportViewer1.ReportSource = rptDoc


    End Sub

    Public Function getAllOrders() As DataTable
        'Connection string replace 'databaseservername' with your db server name
        Dim sqlCon As String = ("myConnectionString")
        Dim Con As SqlConnection = New SqlConnection(sqlCon)
        Dim cmd As SqlCommand = New SqlCommand
        Dim ds As DataSet = Nothing
        Dim adapter As SqlDataAdapter
        Try
            Con.Open()
            'Stored procedure calling. It is already in sample db.
            cmd.CommandText = "Select Top 23 X,Y From myTable"
            cmd.CommandType = CommandType.Text
            cmd.Connection = Con
            ds = New DataSet
            adapter = New SqlDataAdapter(cmd)
            adapter.Fill(ds, "Users")
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            cmd.Dispose()
            If (Con.State <> ConnectionState.Closed) Then
                Con.Close()
            End If
        End Try
        Return ds.Tables(0)
    End Function

End Class
Posted
Updated 2-Jun-14 3:45am
v2
Comments
DamithSL 2-Jun-14 9:58am    
browse your website folder in explorer and go to Bin folder and check whether you have report called "CrystalReport4.rpt" inside the bin folder or not. if it is not there, right click on the "CrystalReport4.rpt" in the solution explorer and go to properties and set the Copy to output directory as always.Let me know if it works :-)
TheWebDeveloper 3-Jun-14 2:14am    
Any ideas???
TheWebDeveloper 3-Jun-14 2:14am    
Ok I Set it to Copy Always but still the report is not displayed in the web page where I placed my report viewer... Any ideas???
DamithSL 3-Jun-14 2:19am    
No I don't have idea about where you put your report viewer :-)
TheWebDeveloper 3-Jun-14 4:15am    
my report viewer is in my asp.net page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900