how can i display crystal report in button_click? am
working with VS2005..........plz help me
Answer / v
protected void Page_Load(object sender, EventArgs e)
{
_ControlId = Request["ControlId"];
CrystalDecisions.CrystalReports.Engine.Database
crDatabase;
CrystalDecisions.CrystalReports.Engine.Table
crTable;
TableLogOnInfo dbConn = new TableLogOnInfo();
_oRpt = new ReportDocument();
// loading the ItemReport in report document
_oRpt.Load(Server.MapPath("~\\reports") + "\\"
+ "RepsAndWar.rpt");
// getting the database, the table and the
LogOnInfo object which holds login information
crDatabase = _oRpt.Database;
// getting the table in an object array of one item
object[] arrTables = new object[1];
crDatabase.Tables.CopyTo(arrTables, 0);
// assigning the first item of array to crTable by
downcasting the object to Table
crTable =
(CrystalDecisions.CrystalReports.Engine.Table)arrTables[0];
dbConn = crTable.LogOnInfo;
// setting values
parseConnString(Settings.CnxBackShop);
dbConn.ConnectionInfo.ServerName = _ServerName;
dbConn.ConnectionInfo.DatabaseName =
_DatabaseName;
dbConn.ConnectionInfo.UserID = _UserID;
dbConn.ConnectionInfo.Password = _Password;
// applying login info to the table object
crTable.ApplyLogOnInfo(dbConn);
crTable.Location =
dbConn.ConnectionInfo.DatabaseName + ".dbo." +
crTable.Location.Substring(crTable.Location.LastIndexOf
(".") + 1);
crTable.LogOnInfo.ConnectionInfo.ServerName =
dbConn.ConnectionInfo.ServerName;
// defining report source
CrystalReportViewer1.ReportSource = _oRpt;
setReportParameters();
}
private void setReportParameters()
{
// all the parameter fields will be added to this
collection
ParameterFields paramFields = new ParameterFields();
// the parameter fields to be sent to the report
ParameterField pfControlId = new ParameterField();
// setting the name of parameter fields with wich
they will be recieved in report
pfControlId.ParameterFieldName = "@ControlId";
// the above declared parameter fields accept
values as discrete objects
// so declaring discrete objects
ParameterDiscreteValue dc_ControlId = new
ParameterDiscreteValue();
// setting the values of discrete objects
dc_ControlId.Value = _ControlId;
// now adding these discrete values to parameters
pfControlId.CurrentValues.Add(dc_ControlId);
// now adding all these parameter fields to the
parameter collection
paramFields.Add(pfControlId);
// finally add the parameter collection to the
crystal report viewer
CrystalReportViewer1.ParameterFieldInfo =
paramFields;
}
protected void btnExport_Click(object sender, EventArgs e)
{
MemoryStream oStream;
oStream = (MemoryStream)_oRpt.ExportToStream
(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
;
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Why multiple Inheritence is not used in C#?
What is predicate c#?
Explain the functionalities of satellite assembly?
i want display a given number into Rupees Format Like Given number is : 156735 my Expected output is 1,56,735. how to display?
What is the difference between an implicit conversion and an explicit conversion?
What are lambda expressions used for?
what is reference parameter? what is out parameters? what is difference these two?
9 Answers Bally Technologies, SPIC, Wipro,
How to find the current application file path while runtime?
Can we define a variable with the access modifier private in an interface?
What is the use of table aliases?
Can a sealed class be used as a base class?
How to put assembly in gac?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)