Value from DataGridViewRow Getting Error in C#

NazHim 201 Reputation points
2021-03-15T10:56:33.867+00:00

hello I am using C# I want to get Column Value from DataGridViewRow using Column Name foreach (DataGridViewRow row in studentsDataGridView.Rows) { MarksOne += Convert.ToDecimal(row.Cells["Stu_MarOne"].Value.ToString()); MarksTwo += Convert.ToDecimal(row.Cells["Stu_MarTwo"].Value.ToString()); MarksThree += Convert.ToDecimal(row.Cells["Stu_MarThre"].Value.ToString()); } Getting Error why? Some Pages it's working perfectly but getting error in this page..? anybody can help me..! Image also attached![77791-screenshot-2021-03-15-155911.png][1] [1]: /api/attachments/77791-screenshot-2021-03-15-155911.png?platform=QnA

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,641 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,386 Reputation points
    2021-03-15T11:19:02.367+00:00

    Looks like you have used the wrong column name, run the following before the failing code to get column names to verify the column name.

    foreach (DataGridViewColumn dataGridViewColumn in studentsDataGridView.Columns)
    {
        Debug.WriteLine(dataGridViewColumn.Name);
    }
    

0 additional answers

Sort by: Most helpful