The input array of your table is too long, Datatable and C #

3

My problem is that I have a datatable of 48 positions that would be the following:

    #region tablaRectificacionesImportaciones


        dt_rectificacionesImportaciones.Columns.AddRange(new DataColumn[48] 
          { 
            new DataColumn("idPedimento", typeof(string)),
            new DataColumn("fecha", typeof(string)),
            new DataColumn("fechaVencimiento",typeof(string)),
            new DataColumn("idCveDocEntrada",typeof(string)),
            new DataColumn("idTipoCambio",typeof(string)),
            new DataColumn("seguros",typeof(string)),
            new DataColumn("fletes",typeof(string)),
            new DataColumn("embalajes",typeof(string)),
            new DataColumn("otros",typeof(string)),
            new DataColumn("valorComercial",typeof(string)),//10
            new DataColumn("valorAduana",typeof(string)),
            new DataColumn("observacion",typeof(string)),
            new DataColumn("dta",typeof(string)),
            new DataColumn("prevalidacion",typeof(string)),
            new DataColumn("factura",typeof(string)),
            new DataColumn("cove",typeof(string)),
            new DataColumn("fechaFactura",typeof(string)),
            new DataColumn("idProveedor",typeof(string)),
            new DataColumn("icoterm",typeof(string)),
            new DataColumn("idMoneda",typeof(string)),//10
            new DataColumn("factorMoneda",typeof(string)),
            new DataColumn("numParte",typeof(string)),
            new DataColumn("idTipoBien",typeof(string)),
            new DataColumn("secuencia",typeof(string)),
            new DataColumn("idFraccion",typeof(string)),
            new DataColumn("idPaisVendedor",typeof(string)),
            new DataColumn("idPaisOrigen",typeof(string)),
            new DataColumn("idUnidadComercial",typeof(string)),
            new DataColumn("cantidad",typeof(string)),
            new DataColumn("precioUnitario",typeof(string)),//10
            new DataColumn("valorAduanaPartida",typeof(string)),
            new DataColumn("idTasa",typeof(string)),
            new DataColumn("preferencia",typeof(string)),
            new DataColumn("idForPago",typeof(string)),
            new DataColumn("idForPagoIVA",typeof(string)),
            new DataColumn("IVA",typeof(string)),
            new DataColumn("pedimentoRectificado",typeof(string)),
            new DataColumn("descargado",typeof(string)),
            new DataColumn("fechaIngreso",typeof(string)),
            new DataColumn("fechaActualizacion",typeof(string)),//10
            new DataColumn("idUsuario",typeof(string)),
            new DataColumn("ipActualizacion",typeof(string)),
            new DataColumn("falta",typeof(string)),
            new DataColumn("cantidadUMT",typeof(string)),
            new DataColumn("iva_f",typeof(string)),
            new DataColumn("fechaRemesa",typeof(string)),//6
            new DataColumn("valorAduana_f",typeof(string)),
            new DataColumn("idEmpresa",typeof(string)) 

          });

        #endregion

Also in a part of my code I fill in that table in the following way:

            //Se recorre la lista lstTablaRectificadoImpo para llenar la tabla dt_rectificacionesImportaciones
            foreach (TablaRectificacion tblRetificaImpo in lstTablaRectificadoImpo)
            {
                dt_rectificacionesImportaciones.Rows.Add(tblRetificaImpo.IdPedimentoOriginal, tblRetificaImpo.Fecha, "", tblRetificaImpo.IdCveDoc, tblRetificaImpo.IdTipoCambio,
                            tblRetificaImpo.Seguros, tblRetificaImpo.Fletes, tblRetificaImpo.Embalajes, tblRetificaImpo.Otros, tblRetificaImpo.ValorComercialME,
                            tblRetificaImpo.ValorAduana, tblRetificaImpo.Observacion, tblRetificaImpo.Dta, tblRetificaImpo.Prevalidacion, tblRetificaImpo.Factura,
                            tblRetificaImpo.Cove, tblRetificaImpo.FechaFactura, tblRetificaImpo.IdProveedor, tblRetificaImpo.Icoterm, tblRetificaImpo.IdMoneda,
                            tblRetificaImpo.FactorMoneda, tblRetificaImpo.NumParte, tblRetificaImpo.IdTipoBien, tblRetificaImpo.Secuencia, tblRetificaImpo.IdFraccion,
                            tblRetificaImpo.IdPaisVendedor, tblRetificaImpo.IdPaisOrigen, tblRetificaImpo.IdUnidadComercial, tblRetificaImpo.Cantidad, tblRetificaImpo.PrecioUnitario,
                            "", tblRetificaImpo.IdTasa, tblRetificaImpo.Preferencia, tblRetificaImpo.IdForPago, tblRetificaImpo.IdForPagoIVA,
                            tblRetificaImpo.IvaFrac, originalRectificado, "", tblRetificaImpo.FechaIngreso, tblRetificaImpo.FechaActualizacion,
                            tblRetificaImpo.IdUsuario, tblRetificaImpo.IpActualizacion, "", "", tblRetificaImpo.IvaFrac,
                            "", tblRetificaImpo.ValorAduana_f,idEmp);
            }

From what I understand this error is because I'm trying to put more data than I initially defined in my table, but I think that is not the real problem, because if you define the correct spaces, in fact the problem arose when adding this value to the table:

empresa

If I remove that value in my for each the following comes out when doing a debug.

If I create the table with my column but it puts a zero by default and if I add the value that should go in that position I get the following error:

  

Input array is longer than the columns in this table

I do not know what is due if my column exists but when adding a value to that column it does not want to work anymore.

    
asked by David 29.03.2017 в 18:11
source

1 answer

2

In the code that you put of the table and the foreach are exactly 48 positions for 48 positions, if you add in foreach empresa the foreach would have 49 positions for 48 positions of the table which is exceeded and generates the error:

  

Input array is longer than the columns in this table

In the case of:

  

If I create the table with my column but it defaults to zero and   if I add the value that should go in that position I get the   next error

the 0 comes from your foreach where you put idEmp which is the 48th position of your table and the foreach uses that variable to fill the 48th position, and for what you comment:

  

From what I understand this error is because I'm trying to   put more data than I initially defined in my table, but I think   that this is not the real problem, because if you define the spaces   correct, in fact the problem arose when adding this value to the   table:

     

company

The value empresa seems to be the value you want to add in position 48 or you would have to add one more field to the table:

new DataColumn("idEmpresa",typeof(string), //<-- posicion 48
new DataColumn("Empresa",typeof(string) //<-- Posicion 49

and your foreach:

tblRetificaImpo.ValorAduana_f, //posicion 47
idEmp, //posicion 48
empresa //posicion 49
    
answered by 29.03.2017 / 18:44
source