In reply to vk7715:
Please use code tags making your code easier to read. I have added them for you.
You have a general problem with the use of foreach loops. You do not declare the iterating variables before the foreach loop, they are implicitly declared local to the loop. If you remove the declaration of int i,j; in your example, you would have gotten an error message that i was undeclared in your array[i].sum constraint because it was outside the foreach loop. Instead it is just using the non-random variable I, which remains at 0. That is why only the first row is getting constrained.
When you want to iterate over multiple dimensions use the this from
foreach (array[i,j]) ...
That declares local variables i and j and iterates over the all their permutations of the ranges.
If instead you write
foreach (array[i][j]) ...
That is supposed to only iterate over the j dimension. However because of a lot of sloppy code, some tools incorrectly iterate over both dimension if i was not previously declared. That is very dangerous code.
And I guess you are in the same course as this person who also wants to know about the same question.