Click here to Skip to main content
13,449,298 members (42,869 online)
Rate this:
Please Sign up or sign in to vote.
Hi guys need help..this is my c# code to print data using crystal report.i have added two subreports named TempItems and TempReciptSummary. before adding TempReciptSummary it works fine..TempReciptSummary does not take any dataset it just has some string type parameters...

DBAccess_TrxView dbt = new DBAccess_TrxView();
            DBAccessStockAdjReport dba_r = new DBAccessStockAdjReport();

            ReportDocument rptDoc = new ReportDocument();

            TempReceptDataSet ds = new TempReceptDataSet();
            DataTable dt = new DataTable();
            dt.TableName = "Crystal Report Example";
            dt = dbt.CrystalReportGRMITEMS(ADVNo);

            ChqTempDataSet ds_ = new ChqTempDataSet();
            DataTable dt_ = new DataTable();
            dt_ = dba_r.CrystalReportChqDetails(ADVNo,"H");


            string path = Path.Combine(Environment.CurrentDirectory, @".\TempReceipt.rpt");
            // Your .rpt file path will be below

            //set dataset to the report viewer.

            rptDoc.SetParameterValue("VenName", txtCusName.Text);
            rptDoc.SetParameterValue("VenID", txtCusId.Text);
            rptDoc.SetParameterValue("Addr1", txtCusAdd1.Text);
            rptDoc.SetParameterValue("Addr2", txtCusAdd2.Text);
            rptDoc.SetParameterValue("Addr3", txtCusAdd3.Text);
            rptDoc.SetParameterValue("GRMNo", ADVNo);
            rptDoc.SetParameterValue("DATAMATION", txtUserId.Text);

           //Parameters for Summary subreport
            float cash = 0f;
            float cheques = 0f;
           float creditcard = 0f;

           if(txtCash.Text.Length != 0)
               cash = float.Parse(txtCash.Text);
            if(txtCheque.Text.Length != 0)
               cheques = float.Parse(txtCheque.Text);
            if(txtCrdtCrd.Text.Length != 0)
               creditcard = float.Parse(txtCrdtCrd.Text);

            rptDoc.SetParameterValue("CASH", cash.ToString("N"), "TempReciptSummary");
            rptDoc.SetParameterValue("CHEQUES", cheques.ToString("N"), "TempReciptSummary");
            rptDoc.SetParameterValue("CREDITCARD", creditcard.ToString("N"), "TempReciptSummary");
            rptDoc.SetParameterValue("AdPaid", lblTotPaid.Text, "TempReciptSummary");
            rptDoc.SetParameterValue("BalDue", lblDueBalance.Text, "TempReciptSummary");
            rptDoc.SetParameterValue("GoodsTotal", lblTotAmount.Text, "TempReciptSummary");
            rptDoc.SetParameterValue("Total", lblTotPaid.Text, "TempReciptSummary");

            System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
            rptDoc.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
            rptDoc.PrintToPrinter(1, true, 0, 0);

            crystalReportViewer1.ReportSource = rptDoc;

My problem is it does not print data and no exception is given..i dubug the code and found that the last line of the code
crystalReportViewer1.ReportSource = rptDoc;
does not execute..after the execution of line
rptDoc.PrintToPrinter(1, true, 0, 0);
it exits..Need your help...Thanks
Posted 24-Dec-12 1:38am
@AmitGajjar 24-Dec-12 8:00am
is your report print label ?
Hard_Rockz 24-Dec-12 8:08am
in there i pass the string value of labels to crystal report parameters
Hard_Rockz 24-Dec-12 14:49pm
found the mistake...i forgot to pass one parameter :) thank you

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180318.3 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100