VB.NET Crystal Reports Load Dynamically
Before proceeding with this tutorial, it is important to note that all programming samples showcased herein are based on the "crystaldb" database. Kindly take a moment to familiarize yourself with the database structure by referring to the following link: Database Structure .
In this particular section, our focus centers around the dynamic passing of User ID, Password, Server Name, and Database Name to Crystal Reports from a VB.NET application. This dynamic approach allows for greater flexibility and adaptability in configuring the Crystal Reports environment.
SITUATIONS :
The ability to pass User ID, Password, Server Name, and Database Name dynamically to Crystal Reports from a VB.NET application proves incredibly valuable in various scenarios. For instance, when developing a database project on a test server that requires migration to another environment, dynamically providing these parameters to Crystal Reports streamlines the transition process.
In the field of VB.NET Crystal Report development, encountering the error message "Failed to open the connection" is not uncommon. This issue often arises when embedding Crystal Reports in a VB.NET application. However, by implementing dynamic logon parameter passing, this problem can be effectively resolved.
In this program, we use our previous work and dynamically pass the required values to Crystal Reports. Before diving into this section, I recommend reviewing the step by step Crystal Report in VB.NET. This guide walks you through the creation of a report that selects all data from the Product table. As this report is static, the ability to change the server dynamically at runtime is not feasible. However, in the present scenario, we overcome this limitation by dynamically passing the Server Name, UserID, and Password to Crystal Reports.
Here we use Crystal Reports ConnectionInfo .
Dim crConnectionInfo As New ConnectionInfo , and pass these arguments to ConnectionInfoSelect the default form (Form1.vb) you created in VB.NET and drag a button and CrystalReportViewer control to your form.
Select Form's source code view and import the following :
- Imports CrystalDecisions.CrystalReports.Engine
- Imports CrystalDecisions.Shared
Put the following source code in the button click event
Full Source VB.NETcryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here.
You have to replace the source code values of "YOUR SERVER NAME" , "YOUR DATABASE NAME" , "YOUR DATABASE USERNAME" , "YOUR DATABASE PASSWORD" with your correct values .
When you run this program you will get the following screen.
- Sample Database and tables for Crystal Reports tutorials
- Step by Step help for creating a simple Crystal Reports in VB.NET
- VB.NET Crystal Reports from multiple tables
- VB.NET Crystal Reports String parameter
- VB.NET Crystal Reports Integer parameter
- VB.NET Crystal Reports Date parameter
- VB.NET Crystal Reports Formula Fields
- VB.NET Crystal Reports Summary Fields
- VB.NET Crystal Reports Export to PDF
- VB.NET Crystal Reports Export to Excel
- Email a Crystal Reports from VB.NET
- Crystal Reports Without Database
- Crystal Report from SQL Query String
- Dynamic Crystal Reports from SQL Query String
- Crystal Reports from XML File
- Create a Subreport in Crystal Reports
- Create a Subreport in Crystal Reports with Link
- How to deploy Crystal Reports on Clinet Machine
- How to create Crystal Reports installer using Merge Modules