Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: I have a question about data binding in my report Post Reply Post New Topic
Author Message
Muquette
Newbie
Newbie


Joined: 13 Dec 2006
Location: Turkey
Online Status: Offline
Posts: 1
Quote Muquette Replybullet Topic: I have a question about data binding in my report
    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...
 
IP IP Logged
Savan
Senior Member
Senior Member
Avatar

Joined: 14 Dec 2007
Location: India
Online Status: Offline
Posts: 162
Quote Savan Replybullet 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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.000 seconds.