我的 try/catch 表达式总是给我一条错误消息,指出“索引超出了数组的范围”,但是该函数以它应该工作的方式完美地工作。唯一的问题是那个烦人的错误。
这是我正在使用的代码:
Try
conn.Open()
Dim Qwery As String = "SELECT a.accid AS 'No', a.setID AS 'ID', l.class AS 'Type', CONCAT(fname,' ',middname,' ',lname ) AS 'Name', date(a.bdate) AS 'BirthDate', l.mail AS 'Acount Name', l.login AS 'Login', l.gender AS 'Gender', l.position AS 'Position', l.department AS 'Department', l.tel AS 'Tel No', l.localno AS 'Office Tel', l.cellno AS 'Cell Phone', l.alt_email AS 'Other Email', l.classif AS 'Classification', l.status AS 'Status' FROM entry a, liist l WHERE a.accid = l.accid AND l.status = '0' ORDER BY a.accid Desc"
Dim smd As MySqlCommand
Dim myreader As MySqlDataReader
smd = New MySqlCommand(Qwery, myconn)
myreader = smd.ExecuteReader
If myreader.Read() = True Then
IdBox.Text = myreader.GetValue(0)
IdNumBox.Text = myreader.GetValue(1)
TypeBox.Text = myreader.GetValue(2)
NameBox.Text = myreader.GetValue(3)
BDayBox.Text = myreader.GetValue(4)
AcNameBox.Text = myreader.GetValue(5)
PassBox.Text = myreader.GetValue(6)
GenBox.Text = myreader.GetValue(7)
PositionBox.Text = myreader.GetValue(8)
DepartmentBox.Text = myreader.GetValue(9)
TelBox.Text = myreader.GetValue(10)
OfficeBox.Text = myreader.GetValue(11)
CellBox.Text = myreader.GetValue(12)
altMailBox.Text = myreader.GetValue(13)
ClassBox.Text = myreader.GetValue(14)
StatusBox.Text = myreader.GetValue(15)
End If
conn.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Message.ToString())
conn.Close()
End Try
我尝试一一删除标签分配的有趣点。并且最多myreader.GetValue(3)
没有出现错误。如果我尝试分配更多标签,它会再次出现。
有谁知道背后的原因?