Input array error to DataTable

  • Thread starter Thread starter labjac
  • Start date Start date
L

labjac

Guest
Hallo

Hope all are well.

I'm not sure how to copy the complete object values into columns, I understand that this is already in array.

but updatedTable.Rows.Add("updated Rows" get the following error: Error Message: Input array is longer than the number of columns in this table. (Seems like to columns is not initialized, but the columns is not fixes and can vary.

Just need to add a row in datatable if condition is true.

private DataTable CalculateUnitsRequired(DataTable Orders)
{
var updatedRows = new tb_ProdTableSqlSymbols();
int skuCompleteStatus = 5;
string message = "";
var updatedTable = new DataTable();
int recordCounter = 0;

try
{
foreach (DataRow dr in Orders.Rows)
{
updatedRows.primkey = Convert.ToInt32(Orders.Rows[recordCounter][0]);
updatedRows.orderNr = Orders.Rows[recordCounter][1].ToString();
updatedRows.waveNo = Convert.ToInt32(Orders.Rows[recordCounter][2]);
updatedRows.pigeonLocation = Orders.Rows[recordCounter][3].ToString();
updatedRows.cartonID = Orders.Rows[recordCounter][4].ToString();
updatedRows.huNr = Orders.Rows[recordCounter][5].ToString();
updatedRows.isGolden = Convert.ToBoolean(Orders.Rows[recordCounter][6]);
updatedRows.skuNr = Orders.Rows[recordCounter][7].ToString();
updatedRows.unitQty = Convert.ToInt32(Orders.Rows[recordCounter][8]);
updatedRows.unitPacked = Convert.ToInt32(Orders.Rows[recordCounter][9]);
updatedRows.unitRemaining = Convert.ToInt32((updatedRows.unitQty - updatedRows.unitPacked)); //Calculate if packs left
updatedRows.consignmentSize = Convert.ToInt32(Orders.Rows[recordCounter][11]);
updatedRows.createdDate = Convert.ToDateTime(Orders.Rows[recordCounter][12]);
updatedRows.status = Convert.ToInt32(Orders.Rows[recordCounter][13]);

if ((updatedRows.unitRemaining <= 0) && (updatedRows.status != skuCompleteStatus)) //Add record to datatable if pack is complete
{
updatedRows.status = skuCompleteStatus;
updatedTable.Rows.Add(updatedRows); //Error happening here when try to add to table.

message = ("Order Nr " + updatedRows.orderNr + " with HuNr " + updatedRows.huNr + " has been packed complete");
LogFiles.EventLogHandler.WriteEvent("3 ; " + this + " ; " + message);
Console.WriteLine(message);
}
recordCounter++;

if (updatedTable.Rows.Count == 0)
{
message = ("Order Nr " + updatedRows.orderNr + " haven't got completed HuNr packed");
LogFiles.EventLogHandler.WriteEvent("3 ; " + this + " ; " + message);
Console.WriteLine(message);
}
}
}
catch (Exception e)
{
LogFiles.ExceptionLogger.WriteException(e);
}
return updatedTable;
}
}
1606753.jpg



labjac

Continue reading...
 
Back
Top