Nozibulla Bashar

Nozibulla Bashar

  • NA
  • 28
  • 7.3k

Calculation of table data and sorting in C#

Apr 7 2015 6:19 AM
I am new to C# and i am building an application on result management where I have two tables named 'student' and 'result'. The primary key of student table is foreign key of result table. In the result table result of different subject a student is stored using the foreign key to identify whose result is it.Now i want to calculate the total result of every student and sort it. From where i can identify who is first.I can calculate total result of a single student but i cant understand how can i calculate total result of all student at a time. I use the below code for calculating result of a single student:
 
SqlDataAdapter sda = new SqlDataAdapter("SELECT tblResult.* FROM  tblResult where [Student ID]='" + studentid + "'and Semester='"+"First"+"'", con);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                dgvShowResult.DataSource = dt;
                int sum = 0;
                for (int i = 0; i < dgvShowResult.Rows.Count; i++)
                {
                    sum += Convert.ToInt32(dgvShowResult.Rows[i].Cells[21].Value);
                } 

Here dgvShowResult is a dataGridView.First i select all result of a student using its ID and then place it in a dataGridView.So i can easily count total marks.

Can anyone suggest me with my problem please...

Answers (5)