Print Page | Close Window

I have a question about data binding in my report

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=50
Printed Date: 03 May 2025 at 8:20pm


Topic: I have a question about data binding in my report
Posted By: Muquette
Subject: I have a question about data binding in my report
Date Posted: 13 Dec 2006 at 1:35am
Could you please help me about data binding?
 
 
I have created in VS 2005 a crystal report and I have put a crystal report viewer on any form but I could not bind my data source to the report and Icould not bind data field object which are on the report.
 
In addition, I did this with my own codes manually .
Is there any way that binding with code ,without visual studio 's vindows?
Or by this way is it impossible to use VS 's own report ?
 
Thanks all...
 



Replies:
Posted By: Savan
Date Posted: 16 Dec 2007 at 8:50pm

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



Print Page | Close Window