Sometimes we need to filter certain data for display under certain circumstances in our programs. Here are some examples fails with which they can achieve to get rows from a datatable, rows must meet certain conditions.
Example 1:
Example 2:
DataTable data = new DataTable("DataTableName");
DataRow[] rows = datos.Select("columnName = 'Value'");
foreach (DataRow row in rows)
{
//do something
}
Example 3:
DataTable dt = new DataTable();
dt = goData(Param);
// FILTERING THE VALUES ABOVE A 2, ONLY TO SHOW THE CURRENT
DataTable newDt = new DataTable();
// LINQ ONLY FOR NEW RECORDS
var query = from d in dt.AsEnumerable()
where Convert.ToInt16(d["value"]) > 2
select d;
// COLLECT THE DATA AND WE INSERT FILTERED IN NEW DATATABLE
newDt = query.CopyToDataTable();
// CAPTURE THE DATATABLE
DataTable dt_Rack = new DataTable();
dt_Rack = (DataTable)ViewState["AMOUNT"];
//LINQ PARA CAPTURAR EL MONTO RACK
// WE PUT INSIDE A DATAROW AMOUNT
IEnumerable<DataRow> q = from d in dt_Rack.AsEnumerable()
where Convert.ToInt16(d["VALUE"]) == VARIABLE
select d;
foreach(DataRow p in q)
{
//do something
}
EEE
See Also:
0 comentarios:
Publicar un comentario