将读取器项存储在数组中 [英] Storing reader item in array

查看:25
本文介绍了将读取器项存储在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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),给出转换错误

Can some one please help me with status(Index) = myReader.Item(0), giving an error with conversion

推荐答案

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

  1. You want your array to grow as elements are added. That's not what arrays are for. Use a List(Of T) instead. (See the examples on MSDN for the exact syntax.)

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

Make sure the data read from the reader has the correct data type. You have two ways of doing that:

  1. 投射它(例如 DirectCast(myReader(0), String))或
  2. (更好)使用已经返回正确数据类型的 reader 方法,例如myReader.GetString(0).

这篇关于将读取器项存储在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆