Since you've said that you
need to query a module based on specific atype_code
, i assume that you want only one module with the given atype_code.
Then you should either use Single/SingleOrDefault or First/FirstOrDefault.
String firstModule = dt.AsEnumerable() .Where(r => r.Field<string>("atype_code") == aTypeCode.Trim()) .Select(r => r.Field<string>("module")) .FirstOrDefault(); // or String singleModule = dt.AsEnumerable() .Where(r => r.Field<string>("atype_code") == aTypeCode.Trim()) .Select(r => r.Field<string>("module")) .SingleOrDefault();
Enumerable.Single throws an exception if there is more than one matching element. That can be useful to validate the data.
Edit:
Here's the query-syntax:
IEnumerable<String> modules = from myAccType in dt.AsEnumerable() where myAccType.Field<string>("atype_code") == aTypeCode.Trim() select myAccType.Field<string>("module"); String module = modules.FirstOrDefault(); // returns null if no matching modules were found