Crystal reports "Attempted to divide by zero" when trying to print but preview is working fine

96 Views Asked by At

I've used a crystal report in winform p.o.s project the problem is that when i try to save or print the report as pdf it gives an error "Attempted to divide by zero" but the preview is working just fine

Here is the code snippet for the print method

  public void PrintReceipt(int id)
    {
        pagesTab.SetPage(7);
        receipt_Template1.SetDataSource(_productService._orderDetails.Where(ol => ol.OrderId == id).ToList());
        var order = _productService._orderList.Where(ol => ol.Id == id).FirstOrDefault();
        var mop = order.ModeOfPayment;
        var amountpaid = order.AmountPaid;
        var totalamount = order.Total;
        var change = order.Change;
        var customerName = order.CustomerName;
        var dateOfPurchase = order.DateOfPurchase;
        var orderId = order.Id;
        receipt_Template1.SetParameterValue("pMop", mop);
        receipt_Template1.SetParameterValue("pAmountPaid", amountpaid);
        receipt_Template1.SetParameterValue("pTotal", totalamount);
        receipt_Template1.SetParameterValue("pChange", change);
        receipt_Template1.SetParameterValue("pCustomerName", customerName);
        receipt_Template1.SetParameterValue("pDateOfPurchase", dateOfPurchase);
        receipt_Template1.SetParameterValue("pOrderId", orderId);
        crystalReportViewer1.ReportSource = receipt_Template1;
    }
}

Here is the rpt file rpt file

Here are the section properties

  • Report header Report header section

  • Page header Page header section

  • Details Details Section

  • Page footer Page footer section

  • Report footer Report footer section

What seems to be causing it ?

I've tried switching some properties like "Suppress" but still it did not work, tried looking at my formula fields but none of them perform any mathematical operations that may result in dividing by zero.

1

There are 1 best solutions below

0
Jessie Kelso On

I've already found the problem turns out "Microsoft to PDF" does not allow small receipt sizes but i still managed to export it as pdf using Crystal Report export to disk " receipt_Template1.ExportToDisk(ExportFormatType.PortableDocFormat, pdfFilePath); "