我如何从我的数据库 [VB.Net/MariaDB] 中获取所有列/行
How do i get all columns / rows from my Database [VB.Net/MariaDB]
我正在尝试使用 MySQL.Data Nuget 获取所有结果,因为我使用的是 MariaDB。但是我的方法只提供了我数据库中的第一个条目,仅此而已。
Public Function getAllFields(ByVal sql As String) As List(Of String)
Dim output As List(Of String) = New List(Of String)
Using cn = New MySqlConnection(connString.ToString())
Using cmd = New MySqlCommand(sql, cn)
cn.Open()
Using rd = cmd.ExecuteReader()
rd.Read()
Dim objs(rd.FieldCount) As Object
Dim quant As Integer = rd.GetValues(objs)
Dim i As Integer
For i = 0 To quant - 1
output.Add(objs(i))
Next i
rd.Close()
End Using
cn.Close()
End Using
End Using
Return output
End Function
读取数据时调用rd.Read
returnsTrue
,否则False
。所以你需要循环直到它 returns False
.
Using rd = cmd.ExecuteReader()
While rd.Read()
Dim objs(rd.FieldCount) As Object
Dim quant As Integer = rd.GetValues(objs)
Dim i As Integer
For i = 0 To quant - 1
output.Add(objs(i))
Next i
End While
End Using
我正在尝试使用 MySQL.Data Nuget 获取所有结果,因为我使用的是 MariaDB。但是我的方法只提供了我数据库中的第一个条目,仅此而已。
Public Function getAllFields(ByVal sql As String) As List(Of String)
Dim output As List(Of String) = New List(Of String)
Using cn = New MySqlConnection(connString.ToString())
Using cmd = New MySqlCommand(sql, cn)
cn.Open()
Using rd = cmd.ExecuteReader()
rd.Read()
Dim objs(rd.FieldCount) As Object
Dim quant As Integer = rd.GetValues(objs)
Dim i As Integer
For i = 0 To quant - 1
output.Add(objs(i))
Next i
rd.Close()
End Using
cn.Close()
End Using
End Using
Return output
End Function
读取数据时调用rd.Read
returnsTrue
,否则False
。所以你需要循环直到它 returns False
.
Using rd = cmd.ExecuteReader()
While rd.Read()
Dim objs(rd.FieldCount) As Object
Dim quant As Integer = rd.GetValues(objs)
Dim i As Integer
For i = 0 To quant - 1
output.Add(objs(i))
Next i
End While
End Using