Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I use following code to populate data in crystal report viewer, when i design report in crystal report, the data is show when i preview, but when use crystal report viewer using following c# code, the data can't show and no any error fetch, this problum is occur only few table, other table report run properly, plz help, i can't understand what can i do.

C#
class RptView
    {
        private ReportDocument rptDoc;
        private ParameterField Parameter;
        private ParameterFields Parameters;
        private ParameterDiscreteValue ParaValue;
        private Connection cnn;



        public void ViewReport(CrystalReportViewer CRViewer, string rptName, Forms.ReportView frm, string ParName, Object ParValue)
        {
            try
            {
              
                cnn = new Connection();
                cnn.ConnectionString();

                rptDoc = new ReportDocument();
                rptDoc.Load(Application.StartupPath + "\\Reports\\" + rptName);
                //rptDoc.Load(Path.GetPathRoot(Application.StartupPath) + "\\Reports\\" + rptName);

                Parameter = new ParameterField();
                Parameter.Name = ParName;
                
                ParaValue = new ParameterDiscreteValue();
                ParaValue.Value = ParValue;

                Parameters = new ParameterFields();
                Parameter.CurrentValues.Add(ParaValue);
                Parameters.Add(Parameter);

                rptDoc.SetDataSource(cnn.ConString());
                rptDoc.Refresh();
                rptDoc.SummaryInfo.ReportAuthor = "";
                CRViewer.ParameterFieldInfo = Parameters;
                CRViewer.ReportSource = rptDoc;
                frm.ShowDialog();

               

            }
            catch(Exception e1) 
            {
                MsgBox.MyMessageBox.ShowBox(e1.Message);
            }

        }

        
        }
    }
Call the report as follows
private void itemStockToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReportView frm = new ReportView();
            RptView rptV = new RptView();

            rptV.ViewReport(frm.CRV, "ItemStock.rpt", frm);
        }
Posted
Updated 24-Aug-12 4:05am
v2

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