Bind crystal reports / sql reports to ADO.NET


 I'm a beginner trying to find out if it's possible to directly connect an sql report/crystal report to an ADO.NET data set?


7/25/2007 9:59:41 AM
📃 7043 articles.

💬 3 Replies

It all depends on what version of Visual studio you are using. Here are the steps for VS2005

In VS2005 you need to do the following:

1) Right click on your solution and select add, New Item.

2) Add a dataset and create your queries in the dataset. Make sure you save this dataset or it will not show up later.

3) Add your reportviewer

4) Right click on your solution and select add new Item Again and then add a crystal report

5) In the crystal report wizard Select crystal reports wizard and the type of report you want

6) Under the data menu you need to select project data, then ADO.NET datasets. Assuming you saved your dataset it will now show up in this field and you can make your selection as well as create your crystal report.

7) Go to your Web page where you want to display the Crystal report and Add a Report viewer to that page: Toolbox, Crystal Reports, Report viewer

8) The code behind:

1    Dim dataSet As DataSet
2    Me.Cursor = Cursors.WaitCursor
3    Dim crReportDocument As CrystalReport1
4    Dim Con As SqlConnection
5    Dim Da As SqlDataAdapter
6    Dim conn As String = "Server=Your Server;Database=Your DB; User ID=sa;Password=Your PW"
7    Con = New SqlConnection(conn)
8    Dim sqlString As String = ""
9    Dim cmSQL As SqlClient.SqlCommand
10   cmSQL = New SqlClient.SqlCommand(sqlString, Con)
11   Con.Open()
12   Da = New SqlDataAdapter(sqlString, Con)
13   dataSet = New DataSet()
14   Da.Fill(dataSet, "This is where you put the name of your dataset created in the steps above")
15   crReportDocument = New CrystalReport1()
16   crReportDocument.SetDataSource(dataSet)
17   CView.ReportSource = crReportDocument
18   Con.Close()
The way you pass SQL connection in line 6 is NOT recommended, but it is easier for me to show you how to do what you need to this way. 
Line 17 (CVIEW) is the name of my report viewer. You can name your report viewer what you want and then change CView to that name.
Hope this helps.
7/25/2007 11:57:25 AM

Thanks for that!

7/27/2007 8:58:48 AM

No Problem,

Let me know if you need more help.

Ps: Don't forget to mark answer if you don't have any more questions.


7/27/2007 1:11:17 PM