Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
Hi , guys...

I want to directly print the report which gets showed in crystalreportviewer..

i tried
rptGP.PrintToPrinter(1, true, 1, 1);


But my report has one parameter and it shows me error that it can't get the parameter value so doesn't print.

my code :

private void printgatepass(string _srno, string _visitorname, string _mobileno, string _company, string _purpose, string _department, string _contactperson, string _city, string _status, string _luggage)
        {
            try
            {
                DataTable dtGatePass = _objVreg.getDataFromQuery("SELECT a.SRNO,a.VISITOR_NAME,a.VISIT_DATE,a.MOBILE_NO,a.COMPANY,a.PURPOSE,b.DEPARTMENT_NAME as DEPARTMENT,c.EMP_NAME as CONTACT_PERSON,a.CITY,a.STATUS FROM VISITOR_REG a,DEPARTMENT b,EMP_DETAILS c WHERE SRNO='" + _srno + "' and a.CONTACT_PERSON=c.EMP_ID and a.DEPARTMENT=b.DEPARTMENT_ID");
               
 DataSet dsGatePass = new DataSet();
                dsGatePass.Tables.Add(dtGatePass.Copy());
                dsGatePass.Tables["Table"].TableName = "dtGatePass";
                Reports.crGatePass rptGP = new Reports.crGatePass();

                DataTable _dttime = _objVreg.gettime(_srno);

                paramField = new ParameterField();
                paramField.Name = "Time";
                ParameterDiscreteValue dsvalue = new ParameterDiscreteValue();
                dsvalue.Value = _dttime.Rows[0][0].ToString();
                paramField.CurrentValues.Add(dsvalue);

                paramFields.Add(paramField);
                rptGP.SetDataSource(dsGatePass);

                CrystalReportViewer1.ParameterFieldInfo = paramFields;
                CrystalReportViewer1.ReportSource = rptGP;
                CrystalReportViewer1.DataBind();
                CrystalReportViewer1.Visible = false;

                rptGP.PrintToPrinter(1, true, 1, 1);
}catch (Exception ex)
         {
             Response.Write(ex.Message);
         }
     }


Please Guide me...Is there any other way i can set parameter value and print the report?
Posted
Updated 9-Sep-16 20:19pm
v3

I think something missing in your code(setting parameter things)....check the below link

C# Crystal Reports parameter[^]

So use the code from above link for setting parameter values.
 
Share this answer
 
v2
try to use rptGP.PrintToPrinter(1, false, 0, 0);
 
Share this answer
 

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