Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
List<string> sList = new List<string>(); 
using (IDataReader _data = dal.ExecuteReader(command))
                       {
                         if(_data !=null)
                           {
                           while (_data.Read())
                           {
                              sList.Add(Convert.ToString(_data["Configkey"]));
}

//Configkey - column name
// slist will have all the rows from table column now I need only set of particular values. How can I get them.
Posted
Updated 5-Oct-15 4:34am
v2

1 solution

Try this:
C#
DataTable dt = new DataTable();
dt.Load(dal.ExecuteReader(command));
var singleValue = dt.AsEnumerable()
    .Where(a=>a.Field<string>("ConfigKey")=="searchedValue")
    .SingleOrDefault();



For further informations, please see:
LINQ to DataSet[^]
LINQ to DataSet Examples[^]
Queries in LINQ to DataSet[^]

[EDIT]

If you can't upgrade your project to newer version of .net framework, use DataTable.Select[^] method.

More at: Filtering and Sorting Directly in Data Tables[^]
 
Share this answer
 
v2
Comments
Tharakharish 5-Oct-15 11:45am    
Thanks for solution,
I have a project solution which is built using .NET framework 2.0 so ASEnumaerable is not supported even the system.data.linq is not supported.so how can I write the linq, can you please provide different solution to achieve it.
Maciej Los 5-Oct-15 11:52am    
See updated answer.
[no name] 5-Oct-15 12:18pm    
My 5.
Maciej Los 5-Oct-15 12:37pm    
Thank you, Bruno.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900