好吧所以我有一个数据库有一些玩家信息,我想为数据库中的每个玩家创建一个标签,因为玩家的数量不是静态的,我在那里放一个代码为我的数据库中的每个记录创建一个标签一切正常,但是所有但是数据库中的第一条记录从未出现过某些原因,如果我提出一个断点,它总是从第二条记录开始,所以这是我的代码到目前为止我真的不知道我是什么#39;我做错了一切对我来说都很好,谢谢你的进步。
Public Class PostionManagement
Dim Dragging As Boolean
Private Sub NewPlayerslabel()
Try
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\HHDB.accdb;")
Dim cmd As New OleDb.OleDbCommand
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT ID, PlayerName, PlayerClass,PlayerRule FROM PlayersDB WHERE (PlayerRule = 'Static')"
cmd.Prepare()
Dim Players = cmd.ExecuteReader
With Players.Read()
Dim PosX As Integer = 25
For Each item In Players
Dim NewPlayer As New Label
NewPlayer.Name = item("ID")
NewPlayer.Location = New Point(12, PosX)
PosX += 25
NewPlayer.Text = item("PlayerName") & " (" & item("PlayerClass") & ")"
NewPlayer.Width = 200
NewPlayer.BackColor = Color.Transparent
If item("PlayerClass") = "Brawler" Or item("PlayerClass") = "Lancer" Then
NewPlayer.ForeColor = Color.Blue
ElseIf item("PlayerClass") = "Mystic" Or item("PlayerClass") = "Priest" Then
NewPlayer.ForeColor = Color.Green
Else
NewPlayer.ForeColor = Color.Red
End If
NewPlayer.Visible = True
AddHandler NewPlayer.MouseDown, AddressOf Newplayer_MouseDown
AddHandler NewPlayer.MouseUp, AddressOf Newplayer_MouseUp
AddHandler NewPlayer.MouseMove, AddressOf Newplayer_MouseMove
Me.Controls.Add(NewPlayer)
Next
End With
con.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Newplayer_MouseDown(sender As Object, e As MouseEventArgs)
Dragging = True
End Sub
Private Sub Newplayer_MouseUp(sender As Object, e As MouseEventArgs)
Dragging = False
End Sub
Private Sub Newplayer_MouseMove(sender As Object, e As MouseEventArgs)
If Dragging = True Then
Dim Point As Point
Dim LableName As Control = CType(sender, Control)
Point = Me.PointToClient(Cursor.Position)
LableName.Top = Point.Y
LableName.Left = Point.X
End If
End Sub
Private Sub PostionManagement_Load(sender As Object, e As EventArgs) Handles MyBase.Load
NewPlayerslabel()
End Sub
End Class
答案 0 :(得分:0)
这是错误的:
With Players.Read()
Dim PosX As Integer = 25
For Each item In Players
我认为你想要的是:
Dim PosX As Integer = 25
While Players.Read()