We can use the following steps to implement Crystal Reports using the Pull Model:
1. Create the .rpt file (from scratch) and set the necessary database connections using the Crystal Report Designer interface.
2. Place a CrystalReportViewer control from the toolbox on the .aspx page and set its properties to point to the .rpt file that we created in the previous step.
3. Call the databind method from your code behind page.
DATABIND METHOD CODE IS AS BELOW
. Create a Dataset during design time.
2. Create the .rpt file (from scratch) and make it point to the Dataset that we created in the previous step.
3. Place a CrystalReportViewer control on the .aspx page and set its properties to point to the .rpt file that we created in the previous step.
4. In your code behind page, write the subroutine to make the connections to the database and populate the dataset that we created previously in step one.
5. Call the Databind method from your code behind page.
Sub BindReport() Dim myConnection As New SqlClient.SqlConnection() myConnection.ConnectionString = "server= (local)\NetSDK;database=pubs;Trusted_Connection=yes" Dim MyCommand As New SqlClient.SqlCommand() MyCommand.Connection = myConnection MyCommand.CommandText = "Select * from Stores" MyCommand.CommandType = CommandType.Text Dim MyDA As New SqlClient.SqlDataAdapter() MyDA.SelectCommand = MyCommand Dim myDS As New Dataset1() 'This is our DataSet created at Design Time MyDA.Fill(myDS, "Stores") 'You have to use the same name as that of your Dataset that you created during design time Dim oRpt As New CrystalReport1() ' This is the Crystal Report file created at Design Time oRpt.SetDataSource(myDS) ' Set the SetDataSource property of the Report to the Dataset CrystalReportViewer1.ReportSource = oRpt ' Set the Crystal Report Viewer's property to the oRpt Report object that we created End Sub
Note: In the above code, you would notice that the object oRpt is an instance of the "Strongly Typed" Report file. If we were to use an "UnTyped" Report then we would have to use a ReportDocument object and manually load the report file into it.
------------- Thanks
Savan
|