Monday, August 19, 2013

How to use filter in datatable using C#.Net?

Some time we need to use filter in our normal DataSet or DataTable to get some values.For that the below example will explain how to use filter in DataTable using C#.Net.

 private void dtFilter()
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("ID"));
    dt.Columns.Add(new DataColumn("Name"));

    dt.Rows.Add("2", "Vijay");
    dt.Rows.Add("1", "Kumar");
    dt.Rows.Add("3", "Yuvan");
    dt.Rows.Add("3", "Vijay");

Filter the records from a datatable in C#:

    DataRow[] dtRow = dt.Select("Name='Vijay'");
    System.Text.StringBuilder str = new System.Text.StringBuilder();

    foreach (DataRow dr in dtRow)
    Response.Write("Filter Output :: " + str.ToString());

Delete records from a datatable using C#.Net:

    foreach (DataRow dr in dtRow)


No comments: