我已经写了一些代码来从我的数据库中检索3个独立的列,但由于某种原因,它没有加载我的查询产生的所有记录。或者,至少它似乎并不这样做。查询不返回所有记录,需要所有记录
另外,出于某种原因,它不会告诉我一个消息箱,它应该告诉我在阅读器关闭后如何阅读howmany记录。
这里是我的代码:
Public Class frmPlayerLocations
Dim str(2), loc As String
Dim xx, yy As Integer
Dim itm As ListViewItem
Private Sub frmPlayerLocations_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ListView1.Columns.Add("ID", 60, HorizontalAlignment.Left)
ListView1.Columns.Add("Name", 115, HorizontalAlignment.Left)
ListView1.Columns.Add("Approximate Location", 115, HorizontalAlignment.Left)
Dim qry = "SELECT profile.unique_id, profile.name, survivor.worldspace FROM profile, survivor WHERE survivor.unique_id = profile.unique_id AND survivor.is_dead = '0' ORDER BY profile.name"
Dim connection As MySqlConnection
connection = New MySqlConnection()
connection.ConnectionString = "Host=" & adminPanel.IP & ";port=" & adminPanel.port & ";user=" & adminPanel.username & ";password=" & adminPanel.password & ";database=" & adminPanel.DBname & ";"
connection.Open()
Dim cmd As New MySqlCommand(qry, connection)
Dim reader As MySqlDataReader = cmd.ExecuteReader()
Dim count As Integer = 0
While reader.Read()
count += 1
str(0) = reader.GetString(0)
str(1) = reader.GetString(1)
loc = reader.GetString(2)
loc = Mid(loc, loc.IndexOf(",") + 3)
xx = CInt(Replace(Mid(loc, 1, loc.IndexOf(",")), ".", ",", 1, -1, CompareMethod.Text))
xx = (xx/10000)
loc = Mid(loc, loc.IndexOf(",") + 2)
yy = CInt(Replace(Mid(loc, 1, loc.IndexOf(",")), ".", ",", 1, -1, CompareMethod.Text))
yy = 152 - (yy/10000)
If xx < 100 Then
If xx < 10 Then
loc = "00" & xx.ToString & " | "
Else
loc = "0" & xx.ToString & " | "
End If
Else : loc = xx.ToString & " | "
End If
If yy < 100 Then
If yy < 10 Then
loc &= "00" & yy.ToString
Else
loc &= "0" & yy.ToString
End If
Else : loc &= yy.ToString
End If
str(2) = loc
itm = New ListViewItem(str)
ListView1.Items.Add(itm)
End While
reader.Close()
connection.Close()
MessageBox.Show(count)
End Sub
End Class
编辑:我注意到,在一排调用表单时的两倍,第二次我得到这个错误:
An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll Additional information: Argument 'Length' must be greater or equal to zero.
它指的是这个行代码:
yy = CInt(Replace(Mid(loc, 1, loc.IndexOf(",")), ".", ",", 1, -1, CompareMethod.Text))
最后但并非最不重要的,VALU ES其在该行的代码中使用:
loc "7.305e-04]]" String
yy 131 Integer
PS:这可能是有益的:它们是在survivor.worldspace的值是在该格式最初:
[168,[1291.16,5343.54,0.27]]