Dim sqlCountQuery As String = "SELECT COUNT(*) FROM codes"
Dim SQLConnection As MySqlConnection = New MySqlConnection
Dim CountCommand As New MySqlCommand(sqlCountQuery, SQLConnection)
SQLConnection.ConnectionString = strServerString
SQLConnection.Open()
reader = CountCommand.ExecuteReader
reader.Read()
CodeCounter = reader.GetInt32(0)
SQLConnection.Close()
Dim sqlQuery As String = "SELECT * FROM codes"
Dim Command As New MySqlCommand(sqlQuery, SQLConnection)
SQLConnection.Open()
reader = Command.ExecuteReader()
reader.Read()
For b = 0 To CodeCounter - 1
test = reader.GetInt32(b)
Next
代码的顶部检索当前存储在数据库中的代码数量,但是当我使用 for 循环进入第二部分时,它正确地从数据库中检索了第一个代码,但之后我收到一条错误消息“你有指定了无效的列序号。”。我一直在逐行运行它,这就是我知道它正确检索第一个代码的方式。