Note that you are increasing i
in the end of every iteration. So in the end i
is greater than the last assigned index by 1. Therefore you need i-1
:
msCommandGetGroup.Parameters.AddWithValue("@id", nummer[i-1]);
Also you might want to have some prechecks here for edge cases, say when there is no rows in dtGetUserid.Rows
.