October 8, 2014

Get datarows a datatable that comply conditions C#


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:

DataTable data = new DataTable("DataTableName"); DataRow[] rows = datos.Select("columnName = 'Value'"); foreach (DataRow row in rows) { //do something }
Example 2:
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();
Example 3:
// 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:


Ditulis Oleh : Angelo Hari: 6:50 PM Kategori:

0 comentarios:

Post a Comment