Filter DataTable in C#
Datatable is used to store data in table form. We may face a situation where we need to filterdatatable in C# code. Hereis how we can load data in datatable.
Below is a table which we will load in datatable in C#.
ID | Name | Address |
1 | Mairaj | Street 1 |
2 | Ahmad | Street 10 |
3 | Minhas | Street 12 |
DataRow []FilteredData = dt.Select("ID = 1");
foreach (DataRow row in FilteredData)
{
Console.WriteLine(FilteredData[0]["ID"]);
}
The result retuned by Select method is an array of DataRow. We can loop through array to get value from each row.
Comments
Post a Comment