VB.NET通过Access数据库循环 [英] VB.NET looping through Access Database

查看:555
本文介绍了VB.NET通过Access数据库循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

使用DataReader可以循环访问数据



示例用法(从 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)
使用连接作为新的OleDbConnection(connectionString)
Dim命令作为新的OleDbCommand(queryString,连接)

connection.Open
$ b Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
Console.WriteLine(reader(0).ToString())
End While b $ b reader.Close()
结束使用
结束Sub

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


替换它

In a VB.NET how can I loop through an an Access database without loading it to a DataGridView or loading it to a DataGridView and unload it after a comparison function finshed its work?

解决方案

Using DataReader you can loop thru data, one row at a time without necessity of loading entire result set into DataTable/GridView.

Example usage (from 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

You pass connection string to your MS Access Database, and SELECT query to run. Example outputs data from the 1st column to console - but you can replace it with your own logic

这篇关于VB.NET通过Access数据库循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆