Click here to Skip to main content
11,795,848 members (72,985 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0 CrystalReports , +
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 at 24-Dec-12 8:00am
is your report print label ?
Hard_Rockz at 24-Dec-12 8:08am
in there i pass the string value of labels to crystal report parameters
Hard_Rockz at 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
0 Maciej Los 410
1 Abhinav S 368
2 OriginalGriff 300
3 Sergey Alexandrovich Kryukov 266
4 KrunalRohit 249
0 OriginalGriff 1,852
1 Maciej Los 1,465
2 KrunalRohit 1,300
3 CPallini 840
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2015
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