0
I’m trying to return data from a list in a foreach. In the first foreach, it is returning the correct data, but it is not recording in the nflist variable of the first foreach, so as soon as it passes through it again, it loses the previous data and overwrites by the current data.
public void UpdateNFE()
{
List<NFE> nfeList = new List<NFE>();
NFEDB nfeData = new NFEDB();
SAPBAPI sapBAPI = new SAPBAPI();
NFE nfeTeste = new NFE();
DataTable NFSap = sapBAPI.SearchNFbyDate();
foreach (DataRow item in NFSap.Rows)
{
int index = NFSap.Rows.IndexOf(item);
nfeList = nfeData.ListNFEForUpdate(NFSap.Rows[index]["J_1BNFDOC-NFENUM"].ToString(), NFSap.Rows[index]["J_1BNFDOC-CREDAT"].ToString());
//está retornando todos os dados corretamente, mas é necessário "gravar"
//os dados retornados
}
foreach (NFE nfe in nfeList)
{
StructureNFEAccessKey nfeAccessKey = new StructureNFEAccessKey();
nfeAccessKey.REGIO = nfe.Region;
}
If you do
nfeList = ...
within theforeach
naturally loses the previous values. If the idea is to add things to the list you will have to use the methodAdd
of the list for that– Isac
Thanks! Worked out with nfeList.Addrange..
– Pat