0
Dim myReader As OleDbDataReader
Dim Index As Integer
Dim status As Array
Index = 0
cmd.CommandText = "SELECT CPALLOCATIONTIME from RECORDMASTER where ID='" & TxtID.Text & "'"
cmd.CommandType = CommandType.Text
myReader = cmd.ExecuteReader()

Do While myReader.Read()
     status(Index) = myReader.Item(0)
     Index = Index + 1
Loop

myReader.Close()

If (Index = 2) Then
If ((status(0) = "Fp" Or status(0) = "Op") And status(1) = "OXp") Then
    qText = TxtSTS.Text + "X"
    Update = True
    ApplicationStatus = 2
ElseIf ((status(0) = "Fp" Or status(0) = "Op") And status(1) = "FXp") Then
    qText = TxtSTS.Text + "X"
    Update = True
    ApplicationStatus = 2
End If

有人可以帮我解决 status(Index) = myReader.Item(0)一下转换错误吗

4

3 回答 3

1
  1. 您希望您的数组随着元素的添加而增长。这不是数组的用途。改用 a List(Of T)。(有关确切语法,请参阅MSDN 上的示例。)

  2. 确保从阅读器读取的数据具有正确的数据类型。你有两种方法可以做到这一点:

    1. 投射它(例如DirectCast(myReader(0), String))或
    2. (更好)使用已经返回正确数据类型的读取器方法,例如myReader.GetString(0).
于 2012-10-30T07:20:31.470 回答
0

尝试

status(Index) = myReader.Item(0).ToString
于 2012-10-30T07:12:04.763 回答
0
Redim status(0) ' < -- declare like this

然后在循环中

Redim preserve status(index)
status(Index) = myReader("Column_name")
index = index + 1
于 2012-10-30T07:13:49.483 回答