3
I have a list as described below
I would like to delete a line from the list mylistnova1
as condition is true.
I try to do as described below but it generates error! Could you please help me?
Abs.
public Datatable Treatquery(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;
}
}
}
Which error is generating and on which line?
– Ricardo
In fact it does not give any error but in compensation, do not delete the line from the list if it is true...
– Joelias Andrade
tries to modify the line
mylistnova1.RemoveAll(item04 => item04 == item04.ItemArray[1]);
formylistnova1.RemoveAll(x => x == item04.ItemArray[1]);
and see if it works– Richard Dias
Puts the declaration of the two lists and if they are objects puts the objects in the question. It is not difficult to exclude no, puts the statements that makes it easier to see the problem
– Ricardo
I updated Carlos the code for full
– Joelias Andrade