How to Pass Parameters in Crystal reports and fecth the records from the sql database in asp.net

By
Hi Friend, Today we will learn"How to pass parameter in Crystal reports and fetch the records from the sql database on behalf of parameter pass in text box".Suppose, you have many records in your database and want to sort the records then you have to sort the records on the basis of any one column value in your database.Here we will pass this parameter value in crystal reports and display the sorted records in crystal reports.then you can download or print this records from the crystal reports. In previous post, you have learned as following. 
There are some steps to implements this whole concepts as given below:-

Step 1:- First Create Crystal reports from Here (Follow step 1 to step 9 only).
Note:-Here,i have used  Student1 table instead of employee table as shown below:-

Step 2:- After performed step 1  ,you will see following output as shown below:-

Step 3:- Now Right click on Parameter fields --> new --> Now Write Name of parameter,Select its Type,Select ValueField and select Description Field as shown below -->OK
Step 4:- Now open Parameter Fields -->Select City --> Press Select Expert -->and select Required fields as shown below:-
Note :- Now Crystal Reports is ready to access with the help of parameter (City).
Step 5:-Now Open  Solution Explorer-->Open Default.aspx  --> Press Smart Tag Right hand side of Crystal Reports Viewe--> Select Choose a Tool Panel view (ParameterPanel) and Unchecked three checked boxes as shown below:-
Step 6:- Now open Default.aspx page--> Drag and Drop one Text Box and Button Controls  from the Toolbox as shown below:-
Step 7:-Now open Default.aspx.cs file -->Write the c# codes on Proceed Button"s click to access the database records with the help of parameter value City as given below:- 

using System;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ReportDocument report1 = new ReportDocument();
        report1.Load(Server.MapPath("CrystalReport1.rpt"));
        report1.SetDatabaseLogon("","","RAMASHANKAR-PC","master");
        report1.SetParameterValue("City",TextBox1.Text);
        CrystalReportViewer1.ReportSource = report1;
    }
}
Descriptions:-
report1.SetDatabaseLogon("","","RAMASHANKAR-PC","master")
Here this method takes four parameters.
  1. User Name
  2. Password
  3. Server Name
  4. Database Name
I have putted First two arguments blanks. If you have already configured user name and password in your sql server database then you can put it on blank space.Otherwise there is no need for this fields, you can access your sql database with other two parameters(sever name and database ) also.
Step 8:- Now Run the application (press F5) --> Now write City Name in Text Box -->Press proceed Button as shown below:-

For More...
  1. How to Add Database .mdf file in asp.net website
  2. How to implement 3 tier architecture with real life example
  3. How to insert data in database and print the Gridview data in windows forms application
  4. How to take print receipt of windows forms application
  5. Call by value and call by reference
  6. File Handling Real concepts
  7. How to make form filling application like IBPS
  8. How to create a calculator application and install it to others computer
  9. How to import excel file data in database and display it in Gridview control
  10. C# Language with Real life Examples
  11. ASP.NET With Real life Examples
  12. ADO.NET With Real life Examples
  13. SQL Server with Real implementation
  14. Complete LINQ Concepts with Examples
  15. Ajax Concepts with Examples
  16. Complete WCF Concepts with Real Examples
  17. Web services with Real life Examples
  18. ASP.NET MCV Concepts with examples
Download Whole Attached File
     Download

0 comments:

Post a Comment

Powered by Blogger.