Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...


C#
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");


            ds.Tables["TempItem"].Merge(dt);
            ds_.Tables["TempCheque"].Merge(dt_);

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

            //set dataset to the report viewer.
            rptDoc.SetDataSource(ds_);
            //rptDoc.DataSourceConnections.Clear();

            rptDoc.Subreports["TempItems"].SetDataSource(ds);
            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
C#
crystalReportViewer1.ReportSource = rptDoc;
does not execute..after the execution of line
C#
rptDoc.PrintToPrinter(1, true, 0, 0);
it exits..Need your help...Thanks
Posted
Comments
AmitGajjar 24-Dec-12 8:00am    
is your report print label ?
Dilan Shaminda 24-Dec-12 8:08am    
in there i pass the string value of labels to crystal report parameters
Dilan Shaminda 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)



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