Skip to content
Advertisement

VB.Net Function Return MySql Results Two Dimensional Array

The following code pulls data from a MySql connection and returns the array (output). This two dimensional array only works when the number of rows and columns are specified before running the query.

Is there a way to get around this? A non-fixed array size? Please help!

Advertisement

Answer

Use this instead

When you have integer use

reader.GetInt32(0)

and so on

To get the correct dimensions for your array

Change your select statement like below

So you have in your result table a column more with the row count in every row.

Now to redim your array. the Columncount you should know. Else you have to add also

So and then you have to adept your datareader

The idea is to get the first row, catch rowcount and redimension the array properly with the right diemnsions. As described you can if you want do the same with with thecoumnsnumber, if you want to be even more flexible.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement