Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.NET Error Populating 2d Array with database field
    primarykey
    data
    text
    <p>i have a query that contains field "kode_brg" i want to fill them into array2d, i'm using mysqldatareader to fill the field into array2d, but it seems that the datareader only read once inside the while looping for more specific, i've added the ss of myproblem belom</p> <p>i'm pretty sure that i've made a mistake in using the <strong>nested for</strong> inside the <strong>while loop</strong></p> <p>could somebody help me fix this problem thanks before regards, me <img src="https://i.stack.imgur.com/oK8kq.png" alt="enter image description here"></p> <p>EDITED: ADDED A CODE TO A QUESTIONS</p> <pre><code> 'FILL X Dim nil_x As String = "SELECT max( kode_faktur ) FROM detail" Dim x As Int32 Dim CMD_X = New MySqlCommand(nil_x, conn.konek) x = Convert.ToInt32(CMD_X.ExecuteScalar()) 'FILL Y Dim nil_y As String = "select max(x.jumlah) from (select count(*) as jumlah from detail group by kode_faktur)x" Dim y As Int32 CMD_Y = New MySqlCommand(nil_y, conn.konek) y = Convert.ToInt32(CMD_Y.ExecuteScalar()) 'LOOPING ARRAY TRANS Dim msql As String = "select kode_brg from detail group by kode_faktur" Dim i, j As Integer Dim arayT(,) As String CMD = New MySqlCommand(msql, conn.konek) 'Try Dim hasil As MySqlDataReader hasil = CMD.ExecuteReader() While hasil.Read() For i = 0 To x ReDim Preserve arayT(x, y) For j = 0 To y arayT(i, j) = hasil("kode_brg") 'Continue For Next j j += 1 'Continue For Next i i += 1 Exit While End While conn.konek.Close() dgv2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing dgv2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders dgv2.RowHeadersVisible = False With Me.dgv2 .DataSource = New Mommo.Data.ArrayDataView(arayT) .SelectionMode = DataGridViewSelectionMode.FullRowSelect .AllowUserToAddRows = False .RowHeadersVisible = True End With </code></pre> <p>one big note from me <strong>DON'T SUGGEST ME TO USE ARRAYLIST/LIST OF/LINQ/DATASET/DATATABLE</strong> because what i really want to do is filling the 2d array with database field, comparing it with another 1d array, then create a new 2d array from both of them, finally i want to display the newly 2d array into the grid.. that's why i chose 2d array instead using dataset to fill my grid</p> <p>i don't know how to compare list(of) or arraylist with 1d array, that's why i'm using 2d array (basic) thanks you before :)</p> <p>the desired output</p> <p><img src="https://i.stack.imgur.com/dJSeh.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload