如何将从数据读取器检索到的列保存到数组中?
我想检索表中大约 800 行的单列,并将这些值保存在数组中,以便稍后引用它们。我该怎么做呢?我尝试过:
con = New OleDb.OleDbConnection("provider=SQLOLEDB;data source=PC;initial catalog=DB1;integrated security=SSPI")
cmd = New OleDbCommand("select col1 from table1", con)
con.Open()
r = cmd.ExecuteReader
While r.Read
prev_ob(i) = r.Item(0)(0)
i = i + 1
End While
For i = 0 To UBound(prev_ob)
Console.WriteLine(prev_ob(i))
Next`
但没有成功。 col1 是 Int64 类型,数组 prev_ob() 也是如此。请让我知道如何将其保存到数组中。
I would like to retrieve a single column of about 800 rows in a table and save these values in an array so as to reference them later on. How can I do it? I tried:
con = New OleDb.OleDbConnection("provider=SQLOLEDB;data source=PC;initial catalog=DB1;integrated security=SSPI")
cmd = New OleDbCommand("select col1 from table1", con)
con.Open()
r = cmd.ExecuteReader
While r.Read
prev_ob(i) = r.Item(0)(0)
i = i + 1
End While
For i = 0 To UBound(prev_ob)
Console.WriteLine(prev_ob(i))
Next`
And it didn't work. The col1 is of type Int64 and so is the array prev_ob(). Please let me know how I can save it to an array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到的错误是什么?更多信息将帮助您更快获得答案。
试试这个:
PS 我编写了一个可以在 C# 中运行的示例,并尝试转换为 VB.net。
What is the error your are getting? More information will help you in getting an answer sooner.
Try this:
PS I wrote a sample that works in C# and tried translating to VB.net.