Hii ,
Data reader reads table rows into the 2d array. The array fills with the last row of the table. How many loops are there?. Why :?:

Input Table :
-----------------------
id red green blue
1101 12 11 13
1102 12 12 14
1103 13 14 13
------------------------
while (reader->Read()) // READS 12 ITEMS (Above)
{
      for(int i=1; i<4; i++) // (loops 3*4 times)
      {
      y_k[i,1] = Convert::ToInt32( reader["id"] );
      y_k[i,2] = Convert::ToInt32( reader["red"] );
      y_k[i,3] = Convert::ToInt32( reader["gren"] );
      y_k[i,4] = Convert::ToInt32( reader["blue"] );
      }
 
}

Edited 4 Years Ago by smurfy: n/a

Each reader->Read() will process 1 row.
You have 4 rows shown, so it (the Read()) will loop 4 times.
The inner loop loops 3 times from 1-to-3
4 on the outside, 3 on the inside. 12 loops.
I was thinking 16 earlier, then realized you start that inner loop at 1 instead of 0.

Now, for that data, you only need the reader to loop because you are specifically putting the data into each "column" of the array.

The "row" of the array is then the only thing that is changing (to keep all of the data).

/*remove the inner loop*/
The only thing that you would keep from that inner loop is the variable i as a counter to tell the 2d array which "row" is used to store the data.

You can increment i manually on each loop of the reader->Read()

Edited 4 Years Ago by thines01: clarity

This question has already been answered. Start a new discussion instead.