VB.NET通过Access数据库循环 [英] VB.NET looping through Access Database
问题描述
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屋!