Tuesday, 8 March 2011

How to create a connection from a SQL Database to Crystal Reports with parameters.

1. Create a new Crystal Report
2. Set the new Crystal Report as a blank report
3. Right click on Database Fields
4. Select Database Expert
5. Expand Create New Connection
6. Double click on OLE DB (ADO)
7. Select OLE DB Provider for SQL Server
8. Click Next >
9. Input name of server
10. Input name of database
11. Check Integrated Security Checkbox
12. Click Next>
13. On the next page click Finish
14. Under Database Expert click on Current Connections
15. Click on database name
16. Click on dbo or specified user
17. Select Table or Stored Procedure
18. Table or Stored Procedure will now be available under Database Fields in the report.
19. Expand Database Fields
20. Expand Table or Stored Procedure
21. Select fields from Table or Stored Procedure and drag on to report.
22. Save the Crystal Report
23. On the web page from toolbox double click on Crystal Report Viewer
24. When the grey Crystal Report Viewer box appear click on the right arrow
25. Under Choose Report Source select
26. In the Create Report Source dialog box, under Specify a Crystal Report, select the Crystal Report you wish to display.
27. Click OK
28. If you do not require parameters debug here otherwise see below for parameters.
29. Enter the following code either on Page Load or with a sub/function and include the Import reference at the top of your document.


Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Reporting
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Dim repDoc As ReportDocument = New ReportDocument
Dim repFilePath = Server.MapPath("~\Reports\CrystalReport.rpt")
repDoc.SetParameterValue(0, )
repDoc.SetParameterValue(1, ))

CrystalReportViewer1.ReportSource = repDoc
CrystalReportViewer1.Visible = True

Or in C#

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Reporting;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

ReportDocument repDoc = new ReportDocument();
dynamic repFilePath = Server.MapPath("~\\Reports\\CrystalReport.rpt");
repDoc.SetParameterValue(0, );
repDoc.SetParameterValue(1, );
CrystalReportViewer1.ReportSource = repDoc;
CrystalReportViewer1.Visible = true;

30. The report is now ready for display, and can be tested using the debugger.

That's how to basically use parameters on a Crystal Report using Visual Studio 2008 with ASP.NET 3.5.

Next will be how to use subGroups within a Crystal Report

No comments:

Post a Comment