就像我们可以在 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/