Friday, January 6, 2012

Get corresponding compare column values from datatable using Linq


public static List<object> GetCorrespondingColumnValue(DataTable dsdatatable, string strCompareColumnName, string strCompareValue, string strReturnColumnName)
        {
            List<object> x = (from r in dsdatatable.AsEnumerable()
                              where (string)r[strCompareColumnName] == strCompareValue.ToString()
                              select r[strReturnColumnName]).ToList();
             

            return x;
        }