Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 782
  • 1.1k
  • 55.7k

Print from report View not working

Dec 7 2023 11:01 AM

Hello Amit,

Please after following your guidance this is the current error I have been seeing, when the first error popup, I commented two line from SNum to SDate but it still popup on the SProductName, and I thought it could be spelling mismatch so I copy  the dtReceipt content to replace them but the same error still show up, the below screen shoot are the errors and the code.

 

 public void LoadReceipt()
        {
        
    ReportDataSource rptReportDataSource;
    try
    {
        DataTable dtReceipt = new DataTable();
        
        this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\rptReceipt.rdlc";
        this.reportViewer1.LocalReport.DataSources.Clear();

        foreach (DataGridViewRow dgvRow in fm.DGVClientBill.Rows)
        {
            DataRow dataRow = dtReceipt.NewRow();
           
            // Assuming column indexes or names match the DataGridView columns
            dataRow["SNum"] = dgvRow.Cells["dgvIDD"].Value.ToString(); // Change the SName with actual DVBClientBill colunm name
            dataRow["SDate"] = Convert.ToDateTime(dgvRow.Cells["dgvDate"].Value);
            dataRow["SProductName"] = dgvRow.Cells["dgvProduct"].Value.ToString();
            dataRow["SPrice"] = Convert.ToDecimal(dgvRow.Cells["dgvSellingPrice2"].Value);
            dataRow["SQty"] = Convert.ToInt32(dgvRow.Cells["dgvQunatity"].Value);
            dataRow["SAmount"] = Convert.ToDecimal(dgvRow.Cells["dgvTotal"].Value);

            dtReceipt.Rows.Add(dataRow);
          
        }

        ReportParameter pTotal = new ReportParameter("pTotal", fm.lblGrandTotal.Text);
        ReportParameter pStore = new ReportParameter("pStore", store);
        ReportParameter pAddress = new ReportParameter("pAddress", address);
        ReportParameter pPhone = new ReportParameter("pPhone", phone);

        reportViewer1.LocalReport.SetParameters(pTotal);
        reportViewer1.LocalReport.SetParameters(pStore);
        reportViewer1.LocalReport.SetParameters(pAddress);
        reportViewer1.LocalReport.SetParameters(pPhone);
        rptReportDataSource = new ReportDataSource("DataSet1", dtReceipt);
        reportViewer1.LocalReport.DataSources.Add(rptReportDataSource);
        reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
        reportViewer1.ZoomMode = ZoomMode.Percent;
        reportViewer1.ZoomPercent = 100;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


Answers (2)