Crystal Reports is a popular Windows-based report writer (report generation program) that allows a programmer to create reports from a variety of data sources with a minimum of written code. Developed by Seagate Software, Crystal Reports can access data from most widely-used databases and can integrate data from multiple databases within one report using Open Database Connectivity.
In this article I will explain how to pass parameters to crystal reports programmatically in ASP.NET. The steps someone needs to follow are:
1. Open crystal report in design mode. Now in Field Explorer select Parameter Fields and right click on it and select New.
2. Select value Type and enter Prompting Text and click OK
3. Our new Parameter field will be added under Parameter Fields in Field Explorer. Now click on Select Export in toolbar section as highlighted in red.
4. When we click Select Expert Choose Field window will open in that select your field click OK Here I am selecting UserName because I want to display the details based on UserName.
5. After click on OK button Select Export window will open in that select operator type as “is equal to” and select “{?Username}” from dropdowns and click OK. Our report ready with parameter now we can access the user details based on Username.
6. Now open CrystalReportViewer Control click on right hand side of smart tag in that uncheck Enable Report Parameter Prompting option because if we run our application that will prompt window for UserName every time.
7. After assign report to CrystalReportViewer control add one textbox and button control to your aspx page after add those controls our page will be like this.
8. Now Open your code behind file and set database connection settings and assign reports to the control before that first add following namespaces.
9. After add namespaces write the following code in code behind.
C# code
VB.NET Code
10. Now run your application and check your output.