I have to get bill_version
from my table reports
where the bill number is maximum
(There can be multiple bill numbers with same value but categorized by their bill_version
)
I'm a newbie to C# and do not know the appropriate syntax regarding the same. So far I'm able to get the maximum bill number in the variable maxBillNumber
. I do not want to run another query for getting that bill version. How can modify this code according to my need?
Here's the code:
int maxBillNumber =0;
if (dt1.Rows.Count > 0)
{
foreach (DataRow dr in dt1.Rows)
{
int bill_number1 = dr.Field<int>("bill_number");
maxBillNumber = Math.Max(maxBillNumber, bill_number1);
}
}
Thanks in advance!
EDIT
I have to get maximum value of another column bill_version
corresponding to that maximum row containing bill_number
without running another query.
bill_number bill_version
1 0
2 0
3 0
4 1
4 2
4 3
I have fetched 4 already. Now I have to get that corresponding 3