php - 在 VB.net 中使用 while 循环打印 MS ACCESS 表

标签 php mysql sql vb.net

就像我们可以在 php 中使用 mysql 轻松完成的那样,我们执行一个查询,然后运行一个 while 循环来打印该查询的所有结果记录。我们如何在 vb.net (2008) 中使用 ms access db 执行此功能。这是我现在用于打印的代码

sql = "SELECT * From Inventory "

        Dim da As New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "Inventory")    
        Label1.Text = ds.Tables("Inventory").Rows(0).Item(2)
        Label2.Text = ds.Tables("Inventory").Rows(1).Item(2)
        Label3.Text = ds.Tables("Inventory").Rows(2).Item(2)

最佳答案

试试这个:

Dim rowCount As Integer = ds.Tables('Inventory').Rows.Count
Dim Labels() As Label = {Label1, Label2, Label3}

foreach label As Label In Labels

  label.Test = ds.Tables('Inventory').Rows(Array.IndexOf(Labels, label)).Item(2)

Next

或者,如果您想通过获取表单上的所有标签来动态获取 Labels() 数组,请将其替换为上面的第 2 行:

Dim Labels() As Label
For Each ctrl In Form1.Controls
    If TypeOf ctrl Is TextBox Then
        nextNum = Labels.Length +1
        ReDim Preserve Labels(nextNum)
        TeamIndex(nextNum) = ctrl
    End If 
Next

关于php - 在 VB.net 中使用 while 循环打印 MS ACCESS 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222624/

相关文章:

java - 通过java程序远程连接mySQL

sql - 如何并行执行 SQL 过程中的子任务

mysql - NEWBIE #1064 - 你的 SQL 语法有错误

sql - 如何避免多次数据库往返和大量无关数据?

php - Angular 显示 php MySQL 结果

PHP/MySQL 安全性——从哪里开始?

mysql - 连接 SQL 列中的选择

php - 在 PHP 中将对象作为参数传递

php - ZendService\WindowsAzure 与 zf2

mysql - 即使没有子记录也需要 View 来计算差异