Hi in this post i will show using LINQ query how to fetch rows from a dataTable for a column starting or ending with any letter,word,Number etc.
Example:
1. here i will fetch rows from a datatable for Names Ending with 'ar'
var query = dtSampleDatatable.AsEnumerable()
.Where(row => row.Field<string>("Name").EndsWith("ar"));
DataTable dtSampleDatatableNew = new DataTable();
dtSampleDatatableNew = query.CopyToDataTable(); // Adding filtered rows to a new datatable.
2. To fetch Names starting with 'ar'
var query = dtSampleDatatable.AsEnumerable()
.Where(row => row.Field<string>("Name").StartsWith("ar"));
DataTable dtSampleDatatableNew = new DataTable();
dtSampleDatatableNew = query.CopyToDataTable(); // Adding filtered rows to a new datatable.
Example:
1. here i will fetch rows from a datatable for Names Ending with 'ar'
var query = dtSampleDatatable.AsEnumerable()
.Where(row => row.Field<string>("Name").EndsWith("ar"));
DataTable dtSampleDatatableNew = new DataTable();
dtSampleDatatableNew = query.CopyToDataTable(); // Adding filtered rows to a new datatable.
2. To fetch Names starting with 'ar'
var query = dtSampleDatatable.AsEnumerable()
.Where(row => row.Field<string>("Name").StartsWith("ar"));
DataTable dtSampleDatatableNew = new DataTable();
dtSampleDatatableNew = query.CopyToDataTable(); // Adding filtered rows to a new datatable.
No comments:
Post a Comment