2017-09-15 79 views
0

我试图使用DataReader()检索并将14个数据库记录存储到变量中。我知道如何将多个字段存储到变量中,但我不知道如何存储一列中的14条记录。我正在使用MS Access和VB。使用DataReader将数据库多个记录存储到变量

Try 
    con.Open() 
    dr = cmd.ExecuteReader() 
    While dr.Read 
     variableName = dr.Item("Description") 
     Now, how can I do it for the other 13 variables????? 
    End While 
    con.Close() 
Catch ex As Exception 
    con.Close() 
    MsgBox(ex.Message) : Exit Sub 
End Try 

回答

0

有一两件事你可以尝试,是创建一个列表变量,然后通过每个数据行使用每个看,周期,列添加到列表中的变量。代码并不准确,但应该有足够的信息来帮助你。

Dim lst as new List(of String) 

    Try 
     con.Open() 
     dr = cmd.ExecuteReader() 
     While dr.Read 
     For Each rw as datarow in dr.Rows() 
      lst.add(rw.item("Description")) 
      Next 
     End While 
     con.Close() 
    Catch ex As Exception 
     con.Close() 
     MsgBox(ex.Message) : Exit Sub 
    End Try 
+0

感谢奥斯汀,但我认为“行()”不是数据读取器的一部分。 – JCLD

相关问题