I have a list as described below
I would like to delete a line from the mylistnova1
list as condition is true.
I try to do as described below but generates error! Could you please help me?
Abs.
public DataTable Query (DataTable table)
{
NewDb openDb3 = new NewDb();
DataTable Carga01 = tabela.Copy();
DataTable Carga02 = tabela.Copy();
//Carrega DataTablepara uma lista
var mylist = tabela.AsEnumerable().ToList();
var mylistnova = tabela.AsEnumerable().ToList();
var mylistnova1 = tabela.AsEnumerable().ToList();
// var mylist1 = ResultadoNovo.AsEnumerable().ToList();
var mylist3 = Carga02.AsEnumerable().ToList();
using (MySqlConnection db = openDb3.AbrirConexaoMySql())
{
try
{
db.Open();
foreach (var Item in mylist3)
{
string renavamrecebe = Convert.ToString(Item.ItemArray[1]);
}
foreach (var item02 in mylist)
{
string renavanRecebido = item02.ItemArray[01].ToString();
string ComparaceuNoCartorio = item02.ItemArray[20].ToString();
Datarecebe = item02.ItemArray[20].ToString();
foreach (var item03 in mylistnova1)
{
string tipocomptaVendaRecebe = Convert.ToString(item03.ItemArray[20]);
Datarecebe1 = Convert.ToString(item03.ItemArray[15]);
renavamContagem = Convert.ToInt32((MamData.MySql.DUT.SelectQuantidadeRenavan(db, renavanRecebido, Datarecebe1)));
if (renavamContagem > 1)
{
if (renavanRecebido == Convert.ToString(item03.ItemArray[1]) && tipocomptaVendaRecebe == "C")
{
// Marco as linhas a serem deletadas
mylistnova1.RemoveAll(x => x == item03.ItemArray[1]);
}
}
}
}
}
catch
{
}
db.Close();
}
DataTable ResultadoNovo = mylistnova1.CopyToDataTable<DataRow>();
return (ResultadoNovo);
}
public DataTable ConvertToDataTable<T>(IList<T> data)
{
PropertyDescriptorCollection properties =
TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
foreach (PropertyDescriptor prop in properties)
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
foreach (T item in data)
{
DataRow row = table.NewRow();
foreach (PropertyDescriptor prop in properties)
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
table.Rows.Add(row);
}
return table;
}
}
}