简体   繁体   中英

how to compare value in one column with other column in datatable C#?

I want to compare all the values in column B with the values in column A using the < operator, then display the results in a label..

i got this code which counts how many data have value < 0 in column A. and displays the result in label.

        int Col_A = Dt.AsEnumerable().Where(x => x.Field<decimal>("Column_A") < 0).Count();
        lbCount.Text = numberOfRecords2.ToString();

what i want is "Column_B < Column_A = result".
Thank you:)

if you want count of the rows where value of Column_A is less than Column_B :

 Dt.AsEnumerable().Where(x => int.Parse(x["Column_A"].ToString()) < int.Parse(x["Column_B"].ToString())).Count();

@Philipe As discussed in comments you could try x => x.Field<decimal>("Column_B") < x.Field<decimal>("Column_A") .

You just need to compare the respective column in place of the hardcoded value 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM