2017-09-15 63 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

相關問題