0
Good morning, I am making an application similar to a sale, which contains sales and sales items. my problem is that I am not able to save the items of sale that is in datagridView, I am using Entity framework, it is only saving a record.
public void InserirItens()
{
ItensToras itens1 = new ItensToras();
try
{
if (dtGridItens.Rows.Count > 1)
{
for (int i = 0; i < dtGridItens.Rows.Count -1; i++)
{
itens1.IdCargas = Convert.ToInt32(dtGridItens.Rows[i].Cells[0].Value);
itens1.IdAlce = Convert.ToInt32(dtGridItens.Rows[i].Cells[1].Value);
context.itensToras.Add(itens1);
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
should instantiate a new object for each time it will insert a new one, ie within the
for
include thisItensToras itens1 = new ItensToras();
– Ricardo Pontual
Friend God bless you, I got thank God thank you very much from my heart.
– Mecleudio Queiroz