All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to see Database Structure .
In this section we are passing User ID , Password , Server Name and Database Name dynamically to Crystal Reports from vb.net .
In many situations this is useful , for example if you develop a database project in a test server and later you have to migrate it , in such situations you have to give these information dynamically to Crystal Reports.
In this program we are using our earlier program and pass the values dynamically to Crystal Reports. Before we start this section take a look at the step by step Crystal Report in VB.NET .
In the step by step Crystal Report we created a report selecting all data from the Product table . There is no chance to change the server on runtime in that case because it is a static report . Here we are passing Server Name , UserID and Password dynamically to the Crystal Reports.
Here we use Crystal Reports ConnectionInfo .
Dim crConnectionInfo As New ConnectionInfo , and pass these arguments to ConnectionInfo
Select 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 :
Put the following source code in the button click event
cryRpt.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.