Wednesday 2 January 2013

Reporting with ASP.NET using C#

Hi! folks, I shall explain this topics step by step. I hope this may help You.

1. Open Sql Server 2005/2008...
2. Create a table as

Create Table CityInfo
(
CityID int Identity,
CityName varchar(50),
PinCode numeric(6),
Places varchar(100)


)

3. Insert Some Values as
Insert into CityInfo values('Delhi',110005,'Patel Nagar')
Insert into CityInfo values('Noida',201301,'Sec 65')

Now Open Visual Studio 2005/2008/2010,

4. Go To FILE->NEW->WEB SITE-> and select ASP.NET WEB SITE and Name It To "CityReport".

5. Open Solution Explorer (Ctrl+W,S) and Add New Item -> Crystal Report (As a Blank Report).
6. Now Go To "CityReport.aspx" and drag Crystal Report Viewer, Click cursor over that and open smart menu
and Choose Report Source -> New Report Source Then You get default Crystal Report Name as "CrystalReportSource1"
leave it as it is and Specify Crystal Report that you just created named "crystalreport.rpt".

7. Open web.config and write connection string
<appSettings>
  <add key="ConnectionString" value="server=your server's name; Database=test_base; uid=sa; pwd=saa;" />
</appSettings>

8. Now Go To "crystalreport.rpt" and Design Your Report simply, enpend Field Explorer and right click over Database
fields and you get Database Expert Option-> Create New Connection -> Expend OLE DB(ADO) ->Microsoft OLE DB Provider for
SQL Server.-> Specify Servername, User ID, Password, DataBase and Integrated Secrity To Checked and Okay.

9. Again you are at DataBase Expert -> Expend test_base (Your Table (CityInfo) ) -> dbo -> Tables -> double click at Your required tables.

10. Now agian in "Crystalreport.rpt" expand Database Engine and select your table and drag all fiels over
section 3 [Details Fields] one by one.

11. Again open "CityReport.aspx.cs" and add these namespace
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

and on Page_Load Event.
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("CrystalReport.rpt"));
        crystalReport.SetDatabaseLogon("sa", "saa", "Your_Server", "test_base");
       
        CrystalReportViewer1.ReportSource = crystalReport;
       
       
12. Finally you can run your aspx page and get report.

Thanks!!!













1 comment: