crear - datatable.rows c#
eliminar datarow de datatable (1)
advRow es un ARRAY. Debe identificar qué fila de la matriz desea eliminar.
dt.Rows.Remove(advRow[0]);
por supuesto, esto solo lo elimina de la tabla de datos, no necesariamente la fuente de datos detrás de ella (sql, xml, ...). Eso requerirá más ...
y sería una buena idea verificar la matriz o iterar la matriz después de seleccionar ...
var datatable = new DataTable();
DataRow[] advRow = datatable.Select("id=1");
datatable.Rows.Remove(advRow[0]);
//of course if there is nothing in your array this will get you an error..
foreach (DataRow dr in advRow)
{
// this is not a good way either, removing an
//item while iterating through the collection
//can cause problems.
}
//the best way is:
for (int i = advRow.Length - 1; i >= 0; i--)
{
datatable.Rows.Remove(advRow[i]);
}
//then with a dataset you need to accept changes
//(depending on your update strategy..)
datatable.AcceptChanges();
Digamos que tengo una tabla de datos dt (contiene anunciantes) y quiero eliminar una fila de dt donde publicSiderID es igual a un valor, ¿cómo puedo hacer eso?
DataTable dt = new DataTable();
//populate the table
dt = DynamicCache.GetAdvertisers();
//I can select a datarow like this:
DataRow[] advRow = dt.Select("advertiserID = " + AdvID);
//how do you remove it, this get''s me an error
dt.Rows.Remove(advRow)
Entonces, ¿cómo lo haces correctamente?
Gracias.