Follow Our FB Page << >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

how can i display crystal report in button_click? am
working with VS2005..........plz help me

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"];


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 =

dbConn = crTable.LogOnInfo;

// setting values
dbConn.ConnectionInfo.ServerName = _ServerName;
dbConn.ConnectionInfo.DatabaseName =
dbConn.ConnectionInfo.UserID = _UserID;
dbConn.ConnectionInfo.Password = _Password;

// applying login info to the table object

crTable.Location =
dbConn.ConnectionInfo.DatabaseName + ".dbo." +
(".") + 1);
crTable.LogOnInfo.ConnectionInfo.ServerName =

// defining report source
CrystalReportViewer1.ReportSource = _oRpt;



private void setReportParameters()
// all the parameter fields will be added to this
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

// setting the values of discrete objects
dc_ControlId.Value = _ControlId;

// now adding these discrete values to parameters

// now adding all these parameter fields to the
parameter collection

// finally add the parameter collection to the
crystal report viewer
CrystalReportViewer1.ParameterFieldInfo =

protected void btnExport_Click(object sender, EventArgs e)
MemoryStream oStream;
oStream = (MemoryStream)_oRpt.ExportToStream
Response.Buffer = true;
Response.ContentType = "application/pdf";


Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What is serialization of data?

0 Answers  

How do you inherit a class into other class in c#?

0 Answers  

Explain the difference between the debug class and trace class?

0 Answers  

How do I create a new form in c#?

0 Answers  

In a site to turn off cookies for one page which method is followed?

0 Answers   Siebel,

How many catch blocks can be there for a single try block?

5 Answers   Clover, HCL,

What is the real use of interface in c#?

0 Answers  

What is literal in c#?

0 Answers  

What is the relationship between a process, application domain, and application?

0 Answers  

what is the diference between casting and converting?

2 Answers  

User's session is explicitly killed by which method ?

0 Answers   Siebel,

What are delegates in C#?

0 Answers   Winsol Solutions,