下面是我試圖用來從GridViewRow中將值傳入DataRow對象(使用Visual Basic的神話語言)的循環。然而,在這條線:在Visual Basic中將GridViewRow數據導入DataRow
dr(i) = r.Cells(i).Text
我不斷收到以下錯誤信息:
the value of type string cannot be converted to system.data.datarow
有人能指出我如何做到這一點正確的方向?
Dim rows As New List(Of GridViewRow)()
For Each item As GridViewRow In grdExpProd.Rows
rows.Add(item)
Next
Dim value As Integer = rows.Count
Dim dt As New DataTable()
For index As Integer = value - 1 To 0 Step -1
Dim dr As DataRow()
Dim r As GridViewRow = rows(index)
For i As Integer = 0 To r.Cells.Count - 1
dr(i) = r.Cells(i).Text
Next
dt.Rows.Add(dr)
Next
Item屬性y應該被當作索引器,所以你不需要用名字來引用它;博士(i)應該足夠了。 – ekolis
@ekolis你是對的,我只是這樣做,以澄清它是類似於GridViewRow的列。 –