Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi guys,

I would like to know how to store a SQL result into an 2d array.

The SQL result is a 13 x 25 table. Because i wish to do calcuations with each element in this result table, i would like each element to be a variable (hence a 2d a array seemed like the best solution).

Im just not sure how to write the SQL query result into a 2D Array.

Please help.


If you return the result into a DataTable, it is already in a 2D array: Row downward, each having Cells across.
Share this answer
nikki88 13-Mar-12 5:04am    
Ok,so how do I reference each element in the datatable for use in the rest of the code? is it the same as an array i.e Arrayname[i,j] ?
OriginalGriff 13-Mar-12 5:18am    
object o = myDataTable.Rows[rowNumber][colNumber];
nikki88 13-Mar-12 6:40am    
Thanks :)
Use Jagged Array[^] to store and then do calculations as you wish.

int[][] sqlResult = new int[13][];
for (int x = 0; x < 12; x++)
   sqlResult[x] = new int[25];
Share this answer
read my[^] article about dynamic pivotting in sql
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900