var query = (from d in _MyDataset.Tables["Records"].AsEnumerable()
where d.Field<String>("Name").Equals("searchText", StringComparison.CurrentCultureIgnoreCase)
select d).OrderBy(x => x.Field<String>("Name"));
if (query.Count() != 0) { DataTable result = query.CopyToDataTable(); }
if _MyDataSet is a DataSet object then the extra cast is not needed in your example.
then create an extension method to create a filtered data table:
public static class DataTableExtensions
{
public static DataTable ReturnColumn(this DataTable dataTable, ICollection<String> fieldNames)
{
if (fieldNames.Count > 0)
{
for (int i = 0; i < dataTable.Columns.Count; i++)
{
DataColumn col = dataTable.Columns[i];
if (!fieldNames.Contains(col.ColumnName))
dataTable.Columns.Remove(col);
}
}
return dataTable;
}
}
you can then filter your datatable like so:
results.ReturnColumn(new List<String> { "Value" });
which will return a data table with only the column "Value"