ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display Group wise Rank in Windows Form DataGridView using C# and VB.Net<p>Hi&nbsp;smile,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">private void btnSearch_Click(object sender, EventArgs e) { string conString = &#34;Server=.;DataBase=Test;UID=sa;PWD=123&#34;; string query = @&#34;SELECT * FROM ( SELECT AdmissionNo,sum(Max) &#39;Total&#39;,sum(Mark) &#39;Obtain&#39; ,dense_rank() over(partition BY SUM(Max) order by SUM(Mark) DESC) AS RANK ,Round(sum(Mark) * 100/ sum(Max),1) as Percentage ,(CASE WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 90 THEN &#39;A+&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 80 THEN &#39;A&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 70 THEN &#39;B&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 60 THEN &#39;C&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 50 THEN &#39;D&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 40 THEN &#39;E&#39; ELSE &#39;FAIL&#39; END ) AS Grade ,(CASE WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 90 THEN &#39;OutStanding&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 80 THEN &#39;Excellent&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 70 THEN &#39;Very Good&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 60 THEN &#39;Good&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 50 THEN &#39;Satisfactory&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 40 THEN &#39;Work Hard&#39; ELSE &#39;FAIL&#39; END ) AS Remarks ,(CASE WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 90 THEN &#39;OutStanding&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 80 THEN &#39;His/Her performance has been outstanding.Keep it up.&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 70 THEN &#39;Keep up the good work.All the best.&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 60 THEN &#39;He/She has the potential to do more.All the best.&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 50 THEN &#39;He/She has been doing good in studies.&#39; WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 40 THEN &#39;He/She needs to work hard in order to improve grades.&#39; ELSE &#39;He/She is advised to pay attention towards studies.&#39; END ) AS TRemarks FROM tblSetMarks WHERE SectionName = @Section AND ClassName = @Class GROUP BY AdmissionNo ) t order by AdmissionNo asc&#34;; DataTable dt = new DataTable(); using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conString)) { using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query)) { cmd.Parameters.AddWithValue(&#34;@Section&#34;, txtSectionName.Text); cmd.Parameters.AddWithValue(&#34;@Class&#34;, txtClassName.Text); using (System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; sda.Fill(dt); } } } dataGridView1.DataSource = dt; }</pre> <p><span style="text-decoration: underline;"><strong>VB.Net</strong></span></p> <pre class="brush: vb">Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click Dim conString As String .;DataBase=Test;UID=sa;PWD=123&#34; Dim query As String = &#34;SELECT * FROM (&#34; _ + &#34;SELECT AdmissionNo,sum(Max) &#39;Total&#39;,sum(Mark) &#39;Obtain&#39;&#34; _ + &#34;,dense_rank() over(partition BY SUM(Max) order by SUM(Mark) DESC) AS RANK&#34; _ + &#34;,Round(sum(Mark) * 100/ sum(Max),1) as Percentage&#34; _ + &#34;,(CASE WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 90 THEN &#39;A+&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 80 THEN &#39;A&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 70 THEN &#39;B&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 60 THEN &#39;C&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 50 THEN &#39;D&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 40 THEN &#39;E&#39;&#34; _ + &#34;ELSE &#39;FAIL&#39; END ) AS Grade&#34; _ + &#34;,(CASE WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 90 THEN &#39;OutStanding&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 80 THEN &#39;Excellent&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 70 THEN &#39;Very Good&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 60 THEN &#39;Good&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 50 THEN &#39;Satisfactory&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 40 THEN &#39;Work Hard&#39;&#34; _ + &#34;ELSE &#39;FAIL&#39; END ) AS Remarks&#34; _ + &#34;,(CASE WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 90 THEN &#39;OutStanding&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 80 THEN &#39;His/Her performance has been outstanding.Keep it up.&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 70 THEN &#39;Keep up the good work.All the best.&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 60 THEN &#39;He/She has the potential to do more.All the best.&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 50 THEN &#39;He/She has been doing good in studies.&#39;&#34; _ + &#34;WHEN Round((SUM(Mark)) * 100/ SUM([Max]),1) &gt;= 40 THEN &#39;He/She needs to work hard in order to improve grades.&#39;&#34; _ + &#34;ELSE &#39;He/She is advised to pay attention towards studies.&#39; END ) AS TRemarks&#34; _ + &#34; FROM tblSetMarks&#34; _ + &#34; WHERE SectionName = @Section AND ClassName = @Class&#34; _ + &#34; GROUP BY AdmissionNo ) t&#34; _ + &#34; order by AdmissionNo asc&#34; Dim dt As DataTable = New DataTable() Using con As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(conString) Using cmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(query) cmd.Parameters.AddWithValue(&#34;@Section&#34;, txtSectionName.Text) cmd.Parameters.AddWithValue(&#34;@Class&#34;, txtClassName.Text) Using sda As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter() cmd.Connection = con sda.SelectCommand = cmd sda.Fill(dt) End Using End Using End Using dataGridView1.DataSource = dt End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/dI63tF1.gif" alt="" width="472" height="284" /></span></strong></p>https://www.aspforums.net:443/Threads/197546/Display-Group-wise-Rank-in-Windows-Form-DataGridView-using-C-and-VBNet/https://www.aspforums.net:443/Threads/197546/Display-Group-wise-Rank-in-Windows-Form-DataGridView-using-C-and-VBNet/Mon, 03 Jun 2019 09:02:22 GMT