1) design Crytal repport
2) Write A select Comand Stored Procedure For Required Fields From The Related tables..
3)Go to View--> Select Solution Explorer-->Right Click on Project -->add new item
4) select Dataset From Templates--> Change the name of dataset
5)go to visual studio menu-->View-->Select Server Explorer
6)Refresh The data Connections--> add new Connection to add your database
7) after adding refresh the data base
8)Open (double click)the datatset that you have added in the solution explorer
9)select the stored procedure you have return for selected fields
10)drag the stored procedure and drop it in dataset
--------------------------------------------------------------------------------------------
Create Stored procedure with the required fields which you want to display in the crystal reports........
example
-------
execute the query........
->Using VS-2008
->right click on project name->Add New Item->Dataset->specify a Name->Click Ok
a form opens with .xsd extension (example:Dataset1.xsd)
------------------------------
Note .You Must Change The The Name...
Don't Give The Name as Dataset.xsd
---------------------------------------
->now open Server Explorer from View Tab in VS-2008
->connect the data connection,select the database stored procedure which u have created(i.e., sp_Demo) from server explorer,now drag the stored procedure which u have created i.e (sp_Demo) and drop it in the .xsd window(i.e Dataset1.xsd)
->build the solution of .xsd window
->->Right click on project name->click on Add new Item->Crystal Reports->specify meaning ful name(i.e CrystalReportDemo.rpt)->click OK->another dialogue box appears->select as a Blank Report i.e second option->click OK
->Crsytal Report window is opened....now design the Crystal view based on ur requirement.......
-->come back to crystal report which u have designd
->right click on database fields in field Explorer
->select Database Expert,a dialogue box appears
->In the right panel of the dialogue box click on ProjectData->ADO.NET Datasets->select the appropriate dataset file which u hve created in step-2(i.e Dataset1)
->select the storedprocedure which u hve created(i.e sp_Demo) and click on '>' button
->click on OK
Now required fields are stored in Database fields in Field Explorer,just click the + symbol beside Database Fields.....
->Now place the dataitems required on the crystal report by drap and drop method
->right click on project name->Add new Item->Class->
->specify a class file with some meaninf ful name(i.e Reports.cs)class file
->inherit system.web.ui.page class to import some features into the Reports class(i.e., public class Reports : System.Web.UI.Page )("public class Reports" is genarated by default just add ": System.Web.UI.Page" to the class name Reports)
->place the following code within some method based on the stored procedure u have created,and pass the required parameters to the method(number of parameters passed to the method should match the parameters passed th the stored procedure).....
--------------------------------------
Note:
////Crystal Report Path="~\\Reports\\CrystalReportDemo.rpt" ////
////Stored Procedure Name=="sp_Demo"
////Your Reports Will Be generate In PDF Format("context.Response.ContentType = "application/pdf""
-----------------------------------------
Write The following code in Reports.cs Class file
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;
public class Reports : System.Web.UI.Page
{
// //Conection Objects Are created in a seperate classs named Connection.cs../ OR you can write connection objects in the page itself/////
->Place the following code in the print button......of the .aspx.cs file
NOTE:The Above process will be displayed in PDF Format....to change the format change the code in Report class file..........
2) Write A select Comand Stored Procedure For Required Fields From The Related tables..
3)Go to View--> Select Solution Explorer-->Right Click on Project -->add new item
4) select Dataset From Templates--> Change the name of dataset
5)go to visual studio menu-->View-->Select Server Explorer
6)Refresh The data Connections--> add new Connection to add your database
7) after adding refresh the data base
8)Open (double click)the datatset that you have added in the solution explorer
9)select the stored procedure you have return for selected fields
10)drag the stored procedure and drop it in dataset
--------------------------------------------------------------------------------------------
step-1
---------Create Stored procedure with the required fields which you want to display in the crystal reports........
example
-------
create proc sp_Demo(@id varchar(50))
as
select s1.*,s2,* from TableA S1,TableB s2 where s1.id=s2.id and s1.id=(some values.....)
execute the query........
step-2
---------->Using VS-2008
->right click on project name->Add New Item->Dataset->specify a Name->Click Ok
a form opens with .xsd extension (example:Dataset1.xsd)
------------------------------
Note .You Must Change The The Name...
Don't Give The Name as Dataset.xsd
---------------------------------------
->now open Server Explorer from View Tab in VS-2008
->connect the data connection,select the database stored procedure which u have created(i.e., sp_Demo) from server explorer,now drag the stored procedure which u have created i.e (sp_Demo) and drop it in the .xsd window(i.e Dataset1.xsd)
->build the solution of .xsd window
step-3
------->->Right click on project name->click on Add new Item->Crystal Reports->specify meaning ful name(i.e CrystalReportDemo.rpt)->click OK->another dialogue box appears->select as a Blank Report i.e second option->click OK
->Crsytal Report window is opened....now design the Crystal view based on ur requirement.......
step-4
-------->come back to crystal report which u have designd
->right click on database fields in field Explorer
->select Database Expert,a dialogue box appears
->In the right panel of the dialogue box click on ProjectData->ADO.NET Datasets->select the appropriate dataset file which u hve created in step-2(i.e Dataset1)
->select the storedprocedure which u hve created(i.e sp_Demo) and click on '>' button
->click on OK
Now required fields are stored in Database fields in Field Explorer,just click the + symbol beside Database Fields.....
->Now place the dataitems required on the crystal report by drap and drop method
step-5
------->right click on project name->Add new Item->Class->
->specify a class file with some meaninf ful name(i.e Reports.cs)class file
->inherit system.web.ui.page class to import some features into the Reports class(i.e., public class Reports : System.Web.UI.Page )("public class Reports" is genarated by default just add ": System.Web.UI.Page" to the class name Reports)
->place the following code within some method based on the stored procedure u have created,and pass the required parameters to the method(number of parameters passed to the method should match the parameters passed th the stored procedure).....
--------------------------------------
Note:
////Crystal Report Path="~\\Reports\\CrystalReportDemo.rpt" ////
////Stored Procedure Name=="sp_Demo"
////Your Reports Will Be generate In PDF Format("context.Response.ContentType = "application/pdf""
-----------------------------------------
Write The following code in Reports.cs Class file
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;
public class Reports : System.Web.UI.Page
{
// //Conection Objects Are created in a seperate classs named Connection.cs../ OR you can write connection objects in the page itself/////
connection obj1 = new connection();
ReportDocument rpt = new ReportDocument();
DataSet1 ds1 = new DataSet1();
ReportDocument rpt = new ReportDocument();
DataSet1 ds1 = new DataSet1();
public void Demoreport(string s)
{
obj1.con.Open();
obj1.cmd = new SqlCommand("sp_Demo", obj1.con);
obj1.cmd.CommandType = CommandType.StoredProcedure;
obj1.cmd.Parameters.AddWithValue("@id", s);
obj1.da = new SqlDataAdapter(obj1.cmd);
obj1.da.Fill(ds1, "sp_Demo");
rpt.Load(Server.MapPath("~\\Reports\\CrystalReportDemo.rpt"));
rpt.SetDataSource(ds1.Tables["sp_Demo"]);
System.Web.HttpContext context = System.Web.HttpContext.Current;
MemoryStream oStream; // using System.IO
oStream = (MemoryStream)
rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
context.Response.Clear();
context.Response.Buffer = true;
context.Response.ContentType = "application/pdf";
context.Response.BinaryWrite(oStream.ToArray());
context.Response.End();
}
step-6
-------->Place the following code in the print button......of the .aspx.cs file
protected void ButtonPrint_Click(object sender, EventArgs e)
{
Reports rpt=new Reports;
rpt.Demoreport(txt_id.text);
}
--------------------
here:
Reports is the Class name Where the Demoreport( string s) Method is Written..
txt_id.text = Parameter Passed...
--------------------
here:
Reports is the Class name Where the Demoreport( string s) Method is Written..
txt_id.text = Parameter Passed...
NOTE:The Above process will be displayed in PDF Format....to change the format change the code in Report class file..........
No comments:
Post a Comment