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)
{
str.Append(dr["Name"].ToString()+",");
}
Response.Write("Filter Output :: " + str.ToString());
Delete records from a datatable using C#.Net:
foreach (DataRow dr in dtRow)
{
dtRow.Rows.Remove(dr);
}
}
No comments:
Post a Comment