Dynamic loading data in crystal report
-
Hi, I have develop an application in vb2005 and want to produce the report in crystal report. From here, does anyone know how to display a report in crystal report (which integrated with vb2005) with a dynamic coding? Thank in advance
Hello, To include the report on the Web page, we need to drag and drop the Crystal Report Viewer control from the Toolbox. Because the Crystal Report Viewer control doesn't have a ReportSource property available at design time, you have to set that property inside your code. Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer #Region " Windows Form Designer generated code " Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load CrystalReportViewer1.ReportSource = Server.MapPath("crystalreport1.rpt") End Sub End Class. or you can create instance of the report class which was created by Visual Studio.NET when you designed your report. The name of that file is same as report that you create CrystalReport1.vb. To see this file expand CrystalReport1.rpt (click on + sign in front of the CrystalReport1.rpt). Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer #Region " Windows Form Designer generated code " Dim crpt As CrystalReport1 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load crpt = New CrystalReport1() CrystalReportViewer1.ReportSource = crpt End Sub End Class. If you set WebForm1.aspx to be the Start Up page for the project, and start the project, you will get the report page if you have blank password in database for "sa". If "sa" or any other user name that you want to use to access database has password, when you run the report, you will see the "LogonFailed" error. If we were developing windows application, Crystal Reports will ask us for password information. This error occured, because when you design and save report, all of the connection information is saved within the report except password. If the password is blank, there will be no problem to create or generate the report. To prevent this, you will need to provide login information in your code before you set ReportSource property. To do so, you will add some code in Page_Load event. Now, your code should look like: Imports CrystalDecisions.CrystalReports.Engine