C# 在c中向存储过程EF插入数组值时出现问题和错误#

C# 在c中向存储过程EF插入数组值时出现问题和错误#,c#,arrays,sql-server,entity-framework,ef-code-first,C#,Arrays,Sql Server,Entity Framework,Ef Code First,我在尝试将数据插入5个数组变量的存储过程时遇到问题。我得到的错误是:System.ArgumentOutOfRangeException:'索引超出范围。必须为非负数且小于集合的大小。参数名称:索引。你能看出我做错了什么吗?变量lotlist、netweightlist、grossweightlist和serialnumberlist可以有1到多个数据插入到我的存储过程中 方法创建存储过程 using System; using System.Collections.Generic; using

我在尝试将数据插入5个数组变量的存储过程时遇到问题。我得到的错误是:System.ArgumentOutOfRangeException:'索引超出范围。必须为非负数且小于集合的大小。参数名称:索引。你能看出我做错了什么吗?变量lotlist、netweightlist、grossweightlist和serialnumberlist可以有1到多个数据插入到我的存储过程中

方法创建存储过程

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BarcodeReceivingApp.Persistence;
using BarcodeReceivingApp.Persistence.Repositories;

namespace BarcodeReceivingApp.Functionality
{
    public class StoredProcedureInsert
    {
        private readonly BarcodeReceivingFootPrintDbContext _barcodeReceivingFootPrintDbContext = new BarcodeReceivingFootPrintDbContext();

        public void CallManualBlindBarcodeParsingEventRequestFootPrintProcedure
        (
            decimal actualPackagedAmount, int actualPackagedPackId, string lotLookupCode,
            int warehouseId, int materialId, string vendorLotLookupCode, DateTime vendorLotManufactureDate, 
            DateTime vendorLotExpirationDate, int shipmentId, decimal netWeight, 
            decimal grossWeight, string serialLookupCode, string licensePlateLookupCode
        )
        {
            _barcodeReceivingFootPrintDbContext.Database
                .ExecuteSqlCommand
                ("EXEC noram_reporting.ManualBlindBarcodeParsingEventRequest " +
                 "@ActualPackagedAmount, @ActualPackagedPackId, @LotLookupCode, @WarehouseId, @MaterialId, @VendorLotLookupCode," +
                 "@VendorLotManufactureDate, @VendorLotExpirationDate, @ShipmentId, @netWeight, @grossWeight, @serialLookupCode, @licensePlateLookupCode",
      new SqlParameter("@ActualPackagedAmount", actualPackagedAmount),
                    new SqlParameter("@ActualPackagedPackId", actualPackagedPackId),
                    new SqlParameter("@LotLookupCode", lotLookupCode),
                    new SqlParameter("@WarehouseId", warehouseId),
                    new SqlParameter("@MaterialId", materialId),
                    new SqlParameter("@VendorLotLookupCode", vendorLotLookupCode),
                    new SqlParameter("@VendorLotManufactureDate", vendorLotManufactureDate),
                    new SqlParameter("@VendorLotExpirationDate", vendorLotExpirationDate),
                    new SqlParameter("@ShipmentId", shipmentId),
                    new SqlParameter("@netWeight", netWeight),
                    new SqlParameter("@grossWeight", grossWeight),
                    new SqlParameter("@serialLookupCode", serialLookupCode),
                    new SqlParameter("@licensePlateLookupCode", licensePlateLookupCode)
                    );
        }
    }
}
private void SendStoredProcedureDataToFootPrint()
        {
            var lotList = _connection.ParseLot();
            var netWeightList = _connection.ParseNetWeight();
            var grossWeightList = _connection.ParseGrossWeight();
            var serialNumberList = _connection.ParseSerialNumber();
            var material = _unitOfWork.Shipments.GetLastMaterialEntry();
            var scanCounts = _connection.CountReceivingBarcodeEntries();
            var packagingId = _unitOfWork.Materials.GetPackagingId();
            var warehouse = _unitOfWork.Warehouses.GetWarehouseIdQuery();
            var shipment = _unitOfWork.Shipments.GetLastShipmentIdEntry();
            var licensePlate = _unitOfWork.LicensePlates.GetLastCreatedLicensePlate();


            try
            {
                for (var i = 0; i <= _connection.GetBarcodeList().Count; i++)
                {
                    _storedProcedureInsert.CallManualBlindBarcodeParsingEventRequestFootPrintProcedure
                    (
                        scanCounts,
                        packagingId,
                        lotList[i],
                        warehouse,
                        5785,
                        lotList[i],
                        DateTime.Now,
                        DateTime.Now,
                        shipment,
                        Convert.ToDecimal(netWeightList[i]) / 100,
                        Convert.ToDecimal(grossWeightList[i]) / 100,
                        serialNumberList[i],
                        licensePlate
                    );
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                throw;
            }
        }
下面是调用该方法将数据插入存储过程的方法

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BarcodeReceivingApp.Persistence;
using BarcodeReceivingApp.Persistence.Repositories;

namespace BarcodeReceivingApp.Functionality
{
    public class StoredProcedureInsert
    {
        private readonly BarcodeReceivingFootPrintDbContext _barcodeReceivingFootPrintDbContext = new BarcodeReceivingFootPrintDbContext();

        public void CallManualBlindBarcodeParsingEventRequestFootPrintProcedure
        (
            decimal actualPackagedAmount, int actualPackagedPackId, string lotLookupCode,
            int warehouseId, int materialId, string vendorLotLookupCode, DateTime vendorLotManufactureDate, 
            DateTime vendorLotExpirationDate, int shipmentId, decimal netWeight, 
            decimal grossWeight, string serialLookupCode, string licensePlateLookupCode
        )
        {
            _barcodeReceivingFootPrintDbContext.Database
                .ExecuteSqlCommand
                ("EXEC noram_reporting.ManualBlindBarcodeParsingEventRequest " +
                 "@ActualPackagedAmount, @ActualPackagedPackId, @LotLookupCode, @WarehouseId, @MaterialId, @VendorLotLookupCode," +
                 "@VendorLotManufactureDate, @VendorLotExpirationDate, @ShipmentId, @netWeight, @grossWeight, @serialLookupCode, @licensePlateLookupCode",
      new SqlParameter("@ActualPackagedAmount", actualPackagedAmount),
                    new SqlParameter("@ActualPackagedPackId", actualPackagedPackId),
                    new SqlParameter("@LotLookupCode", lotLookupCode),
                    new SqlParameter("@WarehouseId", warehouseId),
                    new SqlParameter("@MaterialId", materialId),
                    new SqlParameter("@VendorLotLookupCode", vendorLotLookupCode),
                    new SqlParameter("@VendorLotManufactureDate", vendorLotManufactureDate),
                    new SqlParameter("@VendorLotExpirationDate", vendorLotExpirationDate),
                    new SqlParameter("@ShipmentId", shipmentId),
                    new SqlParameter("@netWeight", netWeight),
                    new SqlParameter("@grossWeight", grossWeight),
                    new SqlParameter("@serialLookupCode", serialLookupCode),
                    new SqlParameter("@licensePlateLookupCode", licensePlateLookupCode)
                    );
        }
    }
}
private void SendStoredProcedureDataToFootPrint()
        {
            var lotList = _connection.ParseLot();
            var netWeightList = _connection.ParseNetWeight();
            var grossWeightList = _connection.ParseGrossWeight();
            var serialNumberList = _connection.ParseSerialNumber();
            var material = _unitOfWork.Shipments.GetLastMaterialEntry();
            var scanCounts = _connection.CountReceivingBarcodeEntries();
            var packagingId = _unitOfWork.Materials.GetPackagingId();
            var warehouse = _unitOfWork.Warehouses.GetWarehouseIdQuery();
            var shipment = _unitOfWork.Shipments.GetLastShipmentIdEntry();
            var licensePlate = _unitOfWork.LicensePlates.GetLastCreatedLicensePlate();


            try
            {
                for (var i = 0; i <= _connection.GetBarcodeList().Count; i++)
                {
                    _storedProcedureInsert.CallManualBlindBarcodeParsingEventRequestFootPrintProcedure
                    (
                        scanCounts,
                        packagingId,
                        lotList[i],
                        warehouse,
                        5785,
                        lotList[i],
                        DateTime.Now,
                        DateTime.Now,
                        shipment,
                        Convert.ToDecimal(netWeightList[i]) / 100,
                        Convert.ToDecimal(grossWeightList[i]) / 100,
                        serialNumberList[i],
                        licensePlate
                    );
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                throw;
            }
        }
private void sendstoredprocessedatatofootprint()
{
var lotList=_connection.ParseLot();
var netWeightList=_connection.ParseNetWeight();
var grossWeightList=_connection.ParseGrossWeight();
var serialNumberList=_connection.ParseSerialNumber();
var material=_unitOfWork.shippings.GetLastMaterialEntry();
var scanCounts=_connection.CountReceivingBarcodeEntries();
var packagingId=_unitOfWork.Materials.GetPackagingId();
var warehouse=_unitOfWork.Warehouses.GetWarehouseIdQuery();
var shipping=_unitOfWork.shippings.getLastShipmentIdentity();
var licensePlate=_unitOfWork.LicensePlates.GetLastCreatedLicensePlate();
尝试
{

for(var i=0;i由于访问数组的无效索引,您在.NET端似乎有异常

for (var i = 0; i <= _connection.GetBarcodeList().Count; i++)

for(var i=0;i由于访问数组的无效索引,您在.NET端出现异常

for (var i = 0; i <= _connection.GetBarcodeList().Count; i++)

for(var i=0;我感谢兄弟,你是对的问题很小,但我想很难看到,呵呵?这通过更改为
i<\u connection.GetBarcodeList()解决了问题.Count;
再次感谢您解决了问题。现在我可以将数据插入存储过程。感谢兄弟,您是对的。问题很小,但我想很难看到,呵呵?通过更改为
I<\u connection.GetBarcodeList()解决了问题.Count;
再次感谢您解决了此问题。现在我可以将数据插入存储过程。