Read IEnumerable List values one by one and insert into table

Basically I need to read a List that has two types of values, one is an ID int, the other is string.

This is what I’ve got:

private async void UpdatePisterosLocal(List<Pisteros> PisterosLista)
        {
            try
            {
                PisterosDBController pistDB = new PisterosDBController();
                Pisteros_Local pistLocal = new Pisteros_Local();

                //this is my code trying to read the list PisterosLista
                foreach (string element in PisterosLista)
                {
                    pistLocal.IDPistero = ??? //don't know what to write here
                    pistLocal.PisteroN = ????
                }
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Answer

This how I finally did it

foreach (var item in PisterosLista)
        {
            var DatosRegistro = new T_Pisteros
            {
                PisteroID = item.PisteroID,
                PisteroN = item.PisteroN
            };
            var num = db.Insert(DatosRegistro); //insert into new DB
        }

Leave a Reply

Your email address will not be published. Required fields are marked *