[Solved] ASP.Net MVC Error: LocalProcessingException: An error occurred during local report processing Index was outside the bounds of the array.

on Oct 28, 2021 10:20 PM


I was tried generate report in .net core mvc 5.0, But I'm confused because the report sometimes working properly and sometimes show the error message like "LocalProcessingException: An error occurred during local report processing.;Index was outside the bounds of the array."

How to solve this ?. Any help could be apriciate.

Below detail of the error massage

LocalProcessingException: An error occurred during local report processing.;Index was outside the bounds of the array.

The Controller.cs

public IActionResult PrintInvoice(string ID_Pembayaran)
    List<PembayaranModel> pembayaran = new List<PembayaranModel>();
    using (SqlConnection con = new SqlConnection(this._configuration.GetConnectionString("Apps_KlinikContext")))
        using (SqlCommand cmd = new SqlCommand())
            cmd.Connection = con;
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = "Select * From View_Print_Invoice Where ID_Pembayaran=@ID_Pembayaran";
            cmd.Parameters.AddWithValue("@ID_Pembayaran", ID_Pembayaran);
            using (SqlDataReader rdr = cmd.ExecuteReader())
                while (rdr.Read())
                    pembayaran.Add(new PembayaranModel
                        Tanggal_Pembayaran = string.Format("{0:dd MMMM yyyy}", rdr["Tanggal_Pembayaran"]).ToString(),
                        NIK_Karyawan = rdr["NIK_Karyawan"].ToString(),
                        Nama_Karyawan = rdr["Nama_Karyawan"].ToString(),
                        Nama_Pasien = rdr["Nama_Pasien"].ToString(),
                        Alamat = rdr["Alamat"].ToString(),
                        Rincian_Pembayaran = rdr["Rincian_Pembayaran"].ToString(),
                        Nama_Obat = rdr["Nama_Obat"].ToString(),
                        Qty = Convert.ToInt32(rdr["Qty"].ToString()),
                        Harga = Convert.ToInt32(rdr["Harga"].ToString()),
                        Total_Bayar = Convert.ToInt32(rdr["Total_Bayar"].ToString())
    string mimtype = "";
    int extension = 1;
    var path = $"{this._webHostEnvironment.WebRootPath}\\Reporting\\Invoice.rdlc";
    LocalReport localReport = new LocalReport(path);
    localReport.AddDataSource("DataSetInvoicePembayaran", pembayaran);
    Dictionary<string, string> parameters = new Dictionary<string, string>();
    parameters.Add("rp1", "Invoice");
    var result = localReport.Execute(RenderType.Pdf, extension, parameters, mimtype);
    return File(result.MainStream, "application/pdf");

The View on Sql Server

SELECT        dbo.Tbl_Pasien.ID_Pasien, dbo.Tbl_Pasien.Nama_Pasien, dbo.Tbl_Pasien.Alamat, dbo.Tbl_Pasien.Tgl_Lahir, dbo.Tbl_Pasien.Jenis_Kelamin, dbo.Tbl_Pasien.Umur, dbo.Tbl_Pasien.Status, dbo.Tbl_Rawat.Tanggal_Di_Rawat,
     dbo.Tbl_Rawat.Keluhan_Pasien, dbo.Tbl_Rawat.Hasil_Diagnosa, dbo.Tbl_Rawat.Tindakan, dbo.Tbl_Rawat.RS_Rujukan, dbo.Tbl_Dokter.Nama_Dokter, dbo.Tbl_Penyakit.Nama_Penyakit, dbo.Tbl_Rawat.ID_Rawat,
     dbo.Tbl_Rawat.ID_Dokter, dbo.Tbl_Rawat.ID_Penyakit
 FROM            dbo.Tbl_Pasien INNER JOIN
     dbo.Tbl_Rawat ON dbo.Tbl_Pasien.ID_Pasien = dbo.Tbl_Rawat.ID_Pasien INNER JOIN
     dbo.Tbl_Dokter ON dbo.Tbl_Rawat.ID_Dokter = dbo.Tbl_Dokter.ID_Dokter INNER JOIN
     dbo.Tbl_Penyakit ON dbo.Tbl_Rawat.ID_Penyakit = dbo.Tbl_Penyakit.ID_Penyakit


Download FREE API for Word, Excel and PDF in ASP.Net: Download