Vb.net 在数组中存储读卡器项

Vb.net 在数组中存储读卡器项,vb.net,Vb.net,有人能帮我处理一下状态(索引)=myReader.Item(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 = Comm

有人能帮我处理一下
状态(索引)=myReader.Item(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
  • 您希望阵列随着元素的添加而增长。这不是数组的用途。改用
    列表(共T个)
    。(有关确切语法,请参见。)

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

  • 强制转换(例如,
    DirectCast(myReader(0),字符串)
    )或
  • (更好)使用已经返回正确数据类型的reader方法,例如
    myReader.GetString(0)
  • status(Index) = myReader.Item(0).ToString
    
    Redim status(0) ' < -- declare like this
    
    Redim preserve status(index)
    status(Index) = myReader("Column_name")
    index = index + 1