0

尝试从表中选择一些记录时遇到此错误消息。

我的脑子现在被枪杀了..有什么想法吗?谢谢!

我的读者是,

Public myReader As SqlCeDataReader
Dim currentMatch(1) As String

cmd.CommandText = "SELECT schoolid,opponent " & _
                  "FROM TEAM_SCHEDULE WHERE seasonid = " & i & _
                  " AND gameid = " & 1 & " ORDER BY id"
myReader = cmd.ExecuteReader()
Do While myReader.Read()
    currentMatch(0) = myReader.GetString(0)
    currentMatch(1) = myReader.GetString(1)
Loop

错误

4

2 回答 2

3

有根据的猜测:

schoolid被定义为INT,但由于某种原因,您使用GetString而不是GetInt32获取它。

Do While myReader.Read()
    currentMatch(0) = myReader.GetInt32(0).ToString()
    currentMatch(1) = myReader.GetString(1)
Loop
于 2012-04-05T19:04:16.483 回答
0

为什么不使用数据表?

 Public myReader As SqlCeDataReader
 Dim currentMatch(1) As String

 cmd.CommandText = "SELECT schoolid,opponent " & _
              "FROM TEAM_SCHEDULE WHERE seasonid = " & i & _
              " AND gameid = " & 1 & " ORDER BY id"
 Dim dt as new DataTable 

 dt.load(cmd.ExecuteReader())

如果需要,可以使用 linq 查询结果数据表

 dim QueryResults = from p as datarow in dt.rows where p.seasonid<10 select p

或选择一个列表

 dim MyObjList = (from p as datarow in dt.rows select seasonid = p.seasonid,  gameid = p.gameid).ToList
于 2012-04-06T09:30:01.183 回答