I'm new to SQL so this might be a basic level problem.
I had a datagridview on C# with 100 rows which has 3 columns : ID from 1 to 100, name of student and mark of Math. I had sort them descending by mark of Math and now I want to divide into 5 parts which is the first 20% of student sorted then I set the Reward column 5 candies, the next 20% of student 4 candies, so on next is 3, 2 and 1 candies.
Here's my code for the 5 candies for the first 20% student because I had sort all the mark descending:
for (int i = 0; i < DataGridView.Rows.Count * 0.2; i++)
{
string sql;
sql = "UPDATE StudentManagement SET Reward= 5 WHERE Name= N'" + DataGridView.Rows[i].Cells[1].Value + "'";
Functions.RunSql(sql);
}
When I run the code I expected all the first 20 rows set to 5 candies in Reward column but it just updated value 5 for only the 19th row. All the first 18 rows and the 20th rows still had NULL value in Reward columns. I think the problem came from the if condition:
i < DataGridView.Rows.Count * 0.2
How can I solve this?