>>string CRefeicao = "01", CFamiliaPrato = "02"; >> >>foreach (DataRow LinhaDetalhe in Detalhe.Rows) >>{ >> string Crefeicao2 = LinhaDetalhe["CRefeicao"].ToString(); >> string CFAmiliaPrato2 = LinhaDetalhe["CFamiliaPrato"].ToString(); >> >> if (CRefeicao == Crefeicao2 & CFamiliaPrato == CFAmiliaPrato2) >> { >> LinhaDetalhe.Delete(); >> } >>} >>>>The problem is: if i have a DataTable with 2 Rows, and the first row fills the condition it will be deleted, then it will remain 1 row in the DataTable. In the 2nd passage of the ForEach loop i'll get an exception: "Colection has been modified. INumerate operation can not be executed.".
> string CRefeicao = "01", CFamiliaPrato = "02"; > string strFilter = > String.Format("CRefeicao = '{0}' and CFamiliaPrato = '{1}'", > CRefeicao, > CFamiliaPrato); > foreach( DataRow row in Detalhe.Select( strFilter ) ) > { > row.Delete(); > } >>Cetin