Editor DataTable on Bulk Update Shows "Object Reference Not Set To an Instance of an Object" Error

Editor DataTable on Bulk Update Shows "Object Reference Not Set To an Instance of an Object" Error

Atif NadeemAtif Nadeem Posts: 5Questions: 3Answers: 0
edited July 2020 in Free community support

Hello there, I am using Datatables Editor in Asp.Net Core 3.0 and I am having an issue on bulk update, when I select up to 50 rows and after changing data it updates successfully,but when i select more than 50 rows like 200 or greater rows it shows error,Null Reference Exception(Object Reference Not Set To an Instance of an Object).

# Kindly let me know how to fix this error.

My Controller Code

        public ActionResult Purchase(Dictionary<string, int> param,string[] LocationId)
        {
     var dbType = "sqlserver";
            var dbConnection = _connectionString;
            using (var db = new Database(dbType, dbConnection))
            {
                try
                {
                    var response = new Editor(db, "PurchaseOrderHistory", "PurchaseOrderHistory.Id")
                        .Model<TempModel>("PurchaseOrderHistory")
                        .Model<CompanyLocation>("CompanyLocations")
                        .Field(new Field("PurchaseOrderHistory.PONo", "PONo"))
                        .Field(new Field("PurchaseOrderHistory.POLineNo", "POLineNo"))
                        .Field(new Field("PurchaseOrderHistory.PODate", "PODate")
                            .Validator(Validation.DateFormat(
                                Format.DATE_ISO_8601,
                                new ValidationOpts { Message = "Please enter a date in the format yyyy-mm-dd" }
                            ))
                             .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
                             .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                        )
                        .Field(new Field("PurchaseOrderHistory.VendorNo", "VendorNo"))
                        .Field(new Field("PurchaseOrderHistory.VendorName", "VendorName"))
                        .Field(new Field("PurchaseOrderHistory.BuyerName", "BuyerName"))
                        .Field(new Field("PurchaseOrderHistory.Material", "Material"))
                        .Field(new Field("PurchaseOrderHistory.VendorOEMMaterialNo", "VendorOEMMaterialNo"))
                        .Field(new Field("PurchaseOrderHistory.Description", "Description"))
                        .Field(new Field("PurchaseOrderHistory.PlantId", "PlantId"))
                        .Field(new Field("PurchaseOrderHistory.OrderQty", 
                         "OrderQty").Validator(Validation.Numeric()).SetFormatter(Format.IfEmpty(Convert.ToDecimal(1))))
                        .Field(new Field("PurchaseOrderHistory.OrderUnit", "OrderUnit"))
                        .Field(new Field("PurchaseOrderHistory.NetPricePerUnit", 
                         "NetPricePerUnit").Validator(Validation.Numeric()).SetFormatter(Format.IfEmpty(Convert.ToDecimal(1))))
                        .Field(new Field("PurchaseOrderHistory.LandedCostFactor", 
                         "LandedCostFactor").Validator(Validation.Numeric()).SetFormatter(Format.IfEmpty(Convert.ToDecimal(1))))
                        .Field(new Field("PurchaseOrderHistory.LandedPOTotalLineValue", "LandedPOTotalLineValue"))
                        .Field(new Field("PurchaseOrderHistory.CompanyId").SetValue(param["CompanyId"]))
                        .Field(new Field("CompanyLocations.LocationCode", "CompanyLocations.LocationCode"))
                        .LeftJoin("CompanyLocations", "CompanyLocations.Id", "=", "PurchaseOrderHistory.LocationId")
                        .Where("PurchaseOrderHistory.CompanyId", param["CompanyId"], "=")
                        .Where(q => q.Where("PurchaseOrderHistory.LocationId", LocationId, "IN", false))
                        .TryCatch(false)
                        .Process(Request)
                        .Data();
                    Dictionary<string, object> returnData = new Dictionary<string, object>();
                    returnData.Add("draw", response.draw);
                    returnData.Add("data", response.data);
                    returnData.Add("recordsTotal", response.recordsTotal);
                    returnData.Add("recordsFiltered", response.recordsFiltered);
                    returnData.Add("error", response.error);
                    returnData.Add("fieldErrors", response.recordsFiltered);
                    returnData.Add("id", response.id);
                    returnData.Add("meta", response.meta);
                    returnData.Add("options", response.options);
                    returnData.Add("searchPanes", response.searchPanes);
                    returnData.Add("files", response.files);
                    returnData.Add("upload", response.upload);
                    returnData.Add("debug", response.debug);
                    returnData.Add("cancelled", response.cancelled);
                    return Json(returnData);
                }
                catch(Exception exc)
                {
                    throw exc;
                }
            }
        }
    }

**## Front End******

 editor = new $.fn.dataTable.Editor({
                ajax: {
                    url: '@Url.Action("purchase","api")',
                    type: 'POST',
                    data: { CompanyId: a, LocationId: b },
                    dataType: "json"
                },
                table: "#datatable",
                fields: [
                    {
                        label: "PO/INV Nr.",
                        name: "PONo",
                    }
                    , {
                        label: "PO/INV Line Nr.",
                        name: "POLineNo"
                    }
                    , {
                        label: "Date:",
                        name: "PODate",
                        type: "datetime",
                        format: 'YYYY-MM-DD',
                        displayFormat: 'YYYY-MM-DD'
                    }
                    ,
                    {
                        label: "Vendor Nr.",
                        name: "VendorNo"
                    }, {
                        label: "Vendor Name:",
                        name: "VendorName"
                    }, {
                        label: "Buyer Name:",
                        name: "BuyerName"
                    }, {
                        label: "Material Nr:",
                        name: "Material"
                    },
                    {
                        label: "OEM Mat. Nr:",
                        name: "VendorOEMMaterialNo"
                    },
                    {
                        label: "Mat Desc:",
                        name: "Description"
                    }, {
                        label: "Plant:",
                        name: "PlantId"
                    }, {
                        label: "Order Qty:",
                        name: "OrderQty"
                    }, {
                        label: "Unit:",
                        name: "OrderUnit"
                    }, {
                        label: "Price per unit:",
                        name: "NetPricePerUnit"
                    }, {
                        label: "Price adj. factor:",
                        name: "LandedCostFactor"
                    }
                    //, {
                    //    label: "PO Total",
                    //    name: "LandedPOTotalLineValue",
                    //    type: 'readonly'
                    //}
                ]
            });
            $('#datatable').DataTable({
                dom: "Blfrtip",
                ajax: {
                    url: '@Url.Action("purchase","api")',
                    type: "POST",
                    data: { CompanyId: a, LocationId: b }
                },
                serverSide: true,
                processing: true,
                scrollX: true,
                sScrollY: 500,
                pageLength: 50,
                columns: [
                    {
                        data: "CompanyLocations.LocationCode", name: "CompanyLocations.LocationCode"
                    },
                    { data: "PONo" }
                    ,
                    { data: "POLineNo" },
                    {
                        data: "PODate", render: function (data) {
                            var returnVal = dateFormat(data);
                            return '<label class="date-width">' + returnVal + '</label>';
                        }
                    },
                    { data: "VendorNo" },
                    { data: "VendorName" },
                    { data: "BuyerName" },
                    { data: "Material" },
                    { data: "VendorOEMMaterialNo" },
                    { data: "Description" },
                    { data: "PlantId" },
                    { data: "OrderQty" },
                    { data: "OrderUnit" },
                    { data: "NetPricePerUnit" },
                    { data: "LandedCostFactor" },
                    { data: "LandedPOTotalLineValue", render: $.fn.dataTable.render.number(',', '.', 0) }
                ],
                select: true,
                buttons: [
                    { extend: "create", editor: editor },
                    { extend: "edit", editor: editor },
                    { extend: "remove", editor: editor },
                    { extend: "selectAll", editor: editor },
                    { extend: 'selectNone', editor: editor },
                ]
            });
        }

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    I suspect you are running in a configured limit in the HTTP server for the number of parameters that it will accept. I presume you are using IIS? You can find information on how to set the limit in this article.

    Allan

This discussion has been closed.