Good afternoon I'm developing an application, which returns a list of note items list, however, I need to populate some fields with the values of each list of items at a time, however, I'm not able to implement the Select () or Where () of the list object?
Method that populates list:
public List<List<ItNota>> SelecionaDadosItNota(out String pstrMsg, out Boolean pbooRetorno, Util.ObjTransf pobjTransf, List<Cliente> plstCliente)
{
List<List<ItNota>> lstListItNota = default(List<List<ItNota>>);
SqlConnection conn = ConexaoBD.CriarConexao(out pstrMsg, out pbooRetorno);
if (pbooRetorno)
{
using (conn)
{
using (SqlCommand cmd = new SqlCommand("uspCtzSelectDadosProd", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@cd_emp", null);
cmd.Parameters.AddWithValue("@nu_rom", null);
cmd.Parameters.AddWithValue("@cd_clien", null);
try
{
lstListItNota = new List<List<ItNota>>();
foreach (var cliente in plstCliente)
{
cmd.Parameters["@cd_emp"].Value = pobjTransf.CdEmp;
cmd.Parameters["@nu_rom"].Value = pobjTransf.NuRom;
cmd.Parameters["@cd_clien"].Value = cliente.CdClien;
using (SqlDataReader rd = cmd.ExecuteReader())
{
if (rd.HasRows)
{
List<ItNota> lstItNota = new List<ItNota>();
while (rd.Read())
{
ItNota itNota = new ItNota();
itNota.CdClien = cliente.CdClien;
itNota.Seq = rd["seq"].ToString();
itNota.Codigo = rd["codigo"].ToString();
itNota.Descricao = rd["descricao"].ToString();
itNota.Valor = rd["valor"].ToString();
itNota.Nf = rd["nf"].ToString();
itNota.Perecivel = rd["perecivel"].ToString();
itNota.Embarcador = rd["embarcador"].ToString();
lstItNota.Add(itNota);
}
lstListItNota.Add(lstItNota);
}
pbooRetorno = true;
}
}
}
catch (SqlException ex)
{
pstrMsg = ex.Message;
pbooRetorno = false;
}
}
}
}
else
{
conn.Close();
}
return lstListItNota;
}
// Busca os dados dos itens da nota
List<List<ItNota>> lstListItNota = seleciona.SelecionaDadosItNota(out pstrMsg, out pbooRetorno, pobjTransf, lstCliente);
Does anyone help me get one item at a time without a Foreach?