简体   繁体   English

错误 CS7036,现有变量中没有正式参数 - ASP.NET C# - MVC

[英]Error CS7036, no formal arguments in existing variables - ASP.NET C# - MVC

I created a solution where the user uploads an excel to a db table named TMP_BEN_DCT through a button on a ASP.NET page using EPPLUS libraries, the code and the db are stored correctly and called on their corresponding classes but I keep gettin a CS7036 on the variables that come from excel file (as soon as I delete one the error shows up on another one):我创建了一个解决方案,其中用户使用 EPPLUS 库通过 ASP.NET 页面上的按钮将 excel 上传到名为 TMP_BEN_DCT 的数据库表,代码和数据库被正确存储并在其相应的类上调用,但我一直在 CS7036 上来自 excel 文件的变量(一旦我删除一个,另一个错误就会出现):

CS7036 No se ha dado ningún argumento que corresponda al parámetro formal requerido 'eTIP_CON' de 'importarController.guardarRegistro(string, string, string, string, string, string, string, benDBEntities)' bulkBeneficios CS7036 没有 se ha dado ningún argumento queresponda al parámetro 正式 requerido 'eTIP_CON' de 'importarController.guardarRegistro(string, string, string, string, string, string, string, benDBEntities)' bulkBeneficios

The following .cs is the entire method to upload:以下 .cs 是整个上传方法:

using OfficeOpenXml;
using System;
using System.Linq;
using System.Web.Mvc;
using bulkBeneficios.Data;

namespace bulkBeneficios.Controllers
{
public class importarController : Controller
{
    // GET: importar
    public ActionResult Index()
    {
        return View("");
    }

    [HttpPost]
    public ActionResult index()
    {
        String mensaje = string.Empty;
        int count = 0;
        importarDatos(out count);
        return View(mensaje);
    }

    private bool importarDatos(out int count)
    {
        var resultado = false;
        int contador = 0;
        count = 0;
        try
        {
            string rutaArchivo = Server.MapPath("/") + "\\importarTest\\";
            var paquete = new ExcelPackage(new System.IO.FileInfo(rutaArchivo));
            int inicioColumna = 1; //Si el excel contiene encabezados o filas vacías al inicio
            int inicioFila = 2; //Al tener encabezados la plantilla se inicia desde fila 2
            ExcelWorksheet planillaTrabajo = paquete.Workbook.Worksheets[1];
            object datos = null;

            TMP_CAR_DCT_BEN db = new TMP_CAR_DCT_BEN(); //ENTIDAD DE TABLA
            benDBEntities db2 = new benDBEntities(); //DB ENTIDAD

            do
            {
                datos = planillaTrabajo.Cells[inicioColumna, inicioFila].Value;

                //leer datos
                //ID_USU_CAR RUT_DCT TIP_CON ID_CON  INI_BEN FIN_BEN MON_CLP

                object eID_USU_CAR = planillaTrabajo.Cells[inicioColumna, inicioFila].Value;
                object eRUT_DCT = planillaTrabajo.Cells[inicioColumna + 1, inicioFila].Value;
                object eTIP_CON = planillaTrabajo.Cells[inicioColumna + 2, inicioFila].Value;
                object eID_CON = planillaTrabajo.Cells[inicioColumna + 3, inicioFila].Value;
                object eINI_BEN = planillaTrabajo.Cells[inicioColumna + 5, inicioFila].Value;
                object eFIN_BEN = planillaTrabajo.Cells[inicioColumna + 6, inicioFila].Value;
                object eMON_CLP = planillaTrabajo.Cells[inicioColumna + 7, inicioFila].Value;


                if (datos != null & eID_USU_CAR != null & eRUT_DCT != null & eTIP_CON != null & eID_CON != null & eINI_BEN != null & eFIN_BEN != null & eMON_CLP != null)
                {
                    //importarDB
                    var esValidoCol1 = guardarRegistro(eID_USU_CAR.ToString(), db2); //CS7036
                    var esValidoCol2 = guardarRegistro(eRUT_DCT.ToString(), db2); //CS7036
                    var esValidoCol3 = guardarRegistro(eTIP_CON.ToString(), db2); //CS7036
                    var esValidoCol4 = guardarRegistro(eID_CON.ToString(), db2); //CS7036
                    var esValidoCol5 = guardarRegistro(eINI_BEN.ToString(), db2); //CS7036
                    var esValidoCol6 = guardarRegistro(eFIN_BEN.ToString(), db2); //CS7036
                    var esValidoCol7 = guardarRegistro(eMON_CLP.ToString(), db2); //CS7036

                    if (esValidoCol1)
                    {
                        count++;
                    }
                }
                inicioFila++;
            }
            while (datos == null);
        }
        catch (Exception ex)
        {

        }
        return resultado;
    }

    public bool guardarRegistro(String eID_USU_CAR, String eRUT_DCT, String eTIP_CON, String eID_CON, String eINI_BEN, String eFIN_BEN, String eMON_CLP, benDBEntities db2)
    {
        var resultado = false;
        try
        {

            //if (db2.ID_USU_CAR.Where(t => t.ID_USU_CAR.Equals(ID_USU_CAR)).Count() == 0)
            //{


            var item1 = new TMP_CAR_DCT_BEN();
            item1.ID_USU_CAR = eID_USU_CAR;
            db2.TMP_CAR_DCT_BEN.Add(item1);
            db2.SaveChanges();


            var item2 = new TMP_CAR_DCT_BEN();
            item2.TIP_CON = eTIP_CON;
            db2.TMP_CAR_DCT_BEN.Add(item2);
            db2.SaveChanges();
            //}
        }
        catch (Exception ex)
        {

        }
        return resultado;
    }
}
}

You defined eight parameters for your method guardarRegistro but you are trying invoke it with only two ?你为你的方法 guardarRegistro 定义了八个参数,但你试图只用两个来调用它? you either have to refactor your method for two arguments你要么必须为两个参数重构你的方法

public bool guardarRegistro(string argument1,benDBEntities db2)
{
//Do your stuffs
}

or invoke using eight parameters或使用八个参数调用

var esValidoCol1 = guardarRegistro(argument1,2,3 ... ,8); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 asp.net 核心 razor 页面 C# 中的页面文件夹中使用 Partial.cshtml 文件的 CS7036 错误消息 - CS7036 error message using a Partial.cshtml file in a Pages folder in asp.net core razor pages C# C# 没有给出与“Receiver(NetworkStream) 错误 CS7036 - C# No argument given that corresponds to the required formal parameter 'stream' of 'Receiver(NetworkStream) Error CS7036 Visual Studio c# 错误 CS7036 方法调用 - Visual Studio c# Error CS7036 Method Call CS7036 C# 如何解决错误按钮 onclick - CS7036 C# How to solve error button onclick CS7036 C#没有给出与c#所需形式参数相对应的参数 - CS7036 C# There is no argument given that corresponds to the required formal parameter of c# C# 中的 Inheritance 问题:CS7036 - Inheritance Issue in C# : CS7036 CS7036 C# 没有给出对应于所需形参的参数 - CS7036 C# There is no argument given that corresponds to the required formal parameter of 错误 CS7036 没有给出与所需形式参数相对应的参数 - Error CS7036 There is no argument given that corresponds to the required formal parameter 尝试创建 class 的新实例时,获取 CS7036 C# 没有给出与所需的形式参数相对应的参数 - When trying to create a new instance of a class get CS7036 C# There is no argument given that corresponds to the required formal parameter of Array.FindAll + Lambda中的CS7036 C# - CS7036 C# in Array.FindAll + Lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM