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

We will filter the table using the ID column where ID value is 1.

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

Popular posts from this blog

Check if ViewBag is null or doesn't exist

Using Progress Bar In C#

Jquery serer side datatables in asp.net