0
 Dim cmd1 As New OleDbCommand("Select * FROM Membros WHERE NFamilia=@nfamilia", con)
    cmd1.Parameters.Add("@nfamilia", OleDbType.VarChar).Value = nfamilia.Text

    con.Open()
    Dim dr2 As OleDbDataReader = cmd1.ExecuteReader()
    While (dr2.Read())
        Dim n As Integer = dr2(1)
        Dim nome As String = dr2(2)
        For i = 1 To 10
            table.Item(n).text = nome
        Next
    End While
    con.Close()

我有这段代码可以在哈希表中插入数据,但是我有一个问题 dr2(1) 它是一个自动增量值,我得到了类似这样的东西

如果我将代码更改为:

            Dim n As Integer 
                n=1
                Dim nome As String = dr2(2)
                For i = 1 To 10
                    table.Item(n).text = nome
                    n=n+1
                Next
            End While

我明白

如果我以这种方式编写代码,我会得到与上面相同的结果

        While (dr2.Read())

        Dim nome As String = dr2(2)
        For i = 1 To 10
            table.Item(i).text = nome
        Next
End While
4

1 回答 1

1

你能试试这个吗?

i = 1
While (dr2.Read())
    table.Item(i).text = dr2(2)
    i = i + 1
End While
于 2012-04-24T12:31:13.953 回答