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)
,给出转化错误
答案 0 :(得分:1)
您希望在添加元素时,您的阵列成长。这不是阵列的用途。请改用List(Of T)
。 (有关确切语法,请参阅examples on MSDN。)
确保从阅读器读取的数据具有正确的数据类型。你有两种方法:
DirectCast(myReader(0), String)
)或myReader.GetString(0)
。 答案 1 :(得分:0)
尝试
status(Index) = myReader.Item(0).ToString
答案 2 :(得分:0)
Redim status(0) ' < -- declare like this
然后在循环
Redim preserve status(index)
status(Index) = myReader("Column_name")
index = index + 1