Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to write code to display crystal report after clicking print button on another form using parameter value?(ex. want to print a customer bill from bill no. Process- select bill no->click on print button->show the particular bill of given bill no.) what code can I write to display this bill properly?
Posted

1 solution

u can try like that this is c# button code but i do not think there would be so much difference between c# and vb code .

// firstly add namespace
C#
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;


C#
protected void btnPrint_Click(object sender, EventArgs e)
    {
        ReportDocument rptDoc = new ReportDocument();
        rptDoc.Load(Server.MapPath("../RPT/crstSubReport.rpt"));
        CrystalDecisions.Shared.TableLogOnInfo loginfo;

        foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in rptDoc.Database.Tables)
        {
            loginfo = myTable.LogOnInfo;
            loginfo.ConnectionInfo.ServerName = @"";
            loginfo.ConnectionInfo.DatabaseName = "";
            loginfo.ConnectionInfo.UserID = "";
            loginfo.ConnectionInfo.Password = "";


            myTable.ApplyLogOnInfo(loginfo);

        }
 MemoryStream stream = (MemoryStream)rptDoc.ExportToStream(ExportFormatType.PortableDocFormat);
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(stream.ToArray());
        rptDoc.Refresh();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900