Look at the error message:
Index was out of range. Must be nonnegative and less than the size of the collection
It couldn;t be a lot clearer if it tried!
You are accessing an array via an index and it is either negative or too big for the array. For example,
int[] m = new int[3];
Can only be access ed as
int i1 = m[0];
int i2 = m[1];
int i3 = m[2];
Any other value will give you this error.
In your code, you are trying to access the DGV at locations
[0,0]
[1,1]
[2,2]
[3,3]
[4,4]
[5,5]
[6,6]
[7,7]
[8,8]
[9,9]
So unless your DGV has at least 10 rows and at least 10 columns, it will fail.
I suspect that you meant to reference a specific column for all the rows, rather than a diagonal.
Why not do a single SqlCommand and with
... WHERE Number_Name = '1' AND Number_of_each_Name BETWEEN 0 AND 9
instead of doing multiple round trips to the server?