将2D数组绑定到Datagrid
所以我的情况是我想从数据库中的两个字段填充2d数组。
我给一个数组赋值为数据库字段
的问题,第二个在datagrid中显示该数组,我已经编码dgv2.Datasource = myArray,但是它仍然返回错误消息。
So my case is that I want to populate a 2d array from two fields in my database. I've got a problem with assigning an array with a value which is a database field and the second one is displaying the array in datagrid, i've coded dgv2.Datasource = myArray but it's still returning an error message.
这是我的代码:
Dim msql As String = "select item_id from detail"
Dim arayT(,) As String
CMD = New MySqlCommand(msql, conn.konek)
Try
Dim res= CMD.ExecuteReader()
While res.Read()
For i As Integer = 0 To x - 1
For j = 0 To y - 1
arayT(i, j) = res.GetString("item_id")
Next j
Next i
End While
Catch ex As Exception
MessageBox.Show("ERROR")
End Try
dgv2.DataSource = arayT
所以我的问题是首先
,如何分配记录列f ROM数据库作为价值进入我的二维数组? (我仍然不确定我的编码是否正确)
其次,如何将2d数组查看到datagrid中,我的意思是将2d数组绑定到datagrid中
So my question is first, how to assign record column from database as value into my 2d array? (i'm still not sure my coding is right) second, how to view the 2d array into datagrid, i mean binding 2d array into datagrid
A来自我的一些请求...请不要让我使用(t)列表或使用LINQ,因为我对它们仍然不太熟悉。
A few requests from me... please don't ask me to use a list of(t) or use LINQ cause I'm still not too familiar with them.
我已经在代码中做了一些修复,但效果不佳。.这是我的最新屏幕截图
i have done some fix in my code but it didn't worked nicely..here is my latest screenshot
大家好,我的问题终于清楚了,这是我的问题的答案
hi guys my questions is finally clear, this is the answer to my question
ReDim Preserve arayT(x, y)
For i = 0 To (x-1)
For j = 0 To (y-1)
hasil.Read()
arayT(i, j) = hasil("kode_brg")
Next j
Next i
原来,我不需要使用一段时间。.
it turned out that i don't need to use while..
非常感谢Afnan,Neolisk和Emmad帮助我回答了我的问题。 :)
many thanks for Afnan, Neolisk and Emmad that had already helped me to answer my questions. :)