I am working on examination result system in vb.net which requires to calculate student ranks based on marks obtained. Subject marks data is stored in database. I am loading the subject marks in a datatable
da.Fill(dt) 'added to a datagridview.
DataGridView1.DataSource = dt
then Add New columns in dt to show result:
dt.Columns.Add("Obtained Marks", GetType(String))
dt.Columns.Add("Percent", GetType(String))
dt.Columns.Add("Result", GetType(String))
dt.Columns.Add("Rank", GetType(Integer))
Then calculated total of all the subjects & added in obtained marks columns by looping through rows & columns of datatable.
For s As Integer = 0 To dt.Rows.Count - 1
For t As Integer = 0 To dt.Columns.Count - 1
obtmarks += CDbl(dt.Rows(s).Item(t))
Next
dt.Rows(s)("Obtained Marks") = obtmarks
dt.Rows(s)("Result") = "PASS"
dt.Rows(s)("Rank") = 'RANK OF STUDENT
Next
How can i calculate rank/position of students on the basis of total marks contained in datatable column "Obtained Marks". i.e. Student with marks 436 Rank should be 1 Student with marks 429.5 Rank should be 2 Student with marks 412 Rank should be 3 ....
so on until all the rows in record. (Image atttached)
if there is any function for datatable which can help here or how can i add the logic in the loop to calculate rank of students and add the value in rank column. Thanks
P.S. I dnt want to sort the rows on obtained marks, but want to Add rank of each student in front of his/her marks, which is already order by their Roll No.