Click here to Skip to main content
Rate this: bad
good
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");
          
            
             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
 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 2:38am
Comments
@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 OriginalGriff 325
1 Sergey Alexandrovich Kryukov 289
2 CPallini 275
3 DamithSL 260
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
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