我想检索我选择的2个项目并将其放入标签中。 这是我的代码。
With lCommand
.Connection = connection
.CommandText = "select pass from officememberprofile where usern = 'CSProfile1' or usern = 'CSProfile2'"
lReader = .ExecuteReader
End With
With lReader
While .Read
Label4.Text = .Item(0)
Label5.Text = .Item(1)
End While
End With
- 预期结果:label4.text应包含CSPass1,label5.text应包含CSPass2,但最终结果是错误的。它只是检索第一个项目。有人可以告诉我如何正确使用while循环并检索其各自标签中的2个项目。谢谢
答案 0 :(得分:0)
每次运行时,都会得到一行结果。你的结果有一列。所以你可以将它存储在一个堆栈中,然后将它们提取到标签中
With lCommand
.Connection = connection
.CommandText = "select pass from officememberprofile where usern = 'CSProfile1' or usern = 'CSProfile2'"
lReader = .ExecuteReader
End With
Dim x As New Stack(Of String)
With lReader
While .Read
x.Push(.Item(0))
End While
End With
Label4.Text = x.Pop()
Label5.Text = x.Pop()