gpt4 book ai didi

database - VB.NET 循环遍历 Access 数据库

转载 作者:搜寻专家 更新时间:2023-10-30 21:52:27 24 4
gpt4 key购买 nike

在 VB.NET 中,我如何循环访问 Access 数据库而不将其加载到 DataGridView 或将其加载到 DataGridView 并在比较函数后卸载它完成工作了吗?

最佳答案

使用 DataReader,您可以遍历数据,一次一行,而无需将整个结果集加载到 DataTable/GridView 中。

示例用法(来自 http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdatareader(v=vs.90).aspx )

Public Sub ReadData(ByVal connectionString As String, _
ByVal queryString As String)
Using connection As New OleDbConnection(connectionString)
Dim command As New OleDbCommand(queryString, connection)

connection.Open()

Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
Console.WriteLine(reader(0).ToString())
End While
reader.Close()
End Using
End Sub

您将连接字符串传递给您的 MS Access 数据库,并运行 SELECT 查询。示例将第一列的数据输出到控制台 - 但您可以用自己的逻辑替换它

关于database - VB.NET 循环遍历 Access 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11729479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com