【问题标题】:How do i get all columns / rows from my Database [VB.Net/MariaDB]如何从我的数据库中获取所有列/行 [VB.Net/MariaDB]
【发布时间】:2019-12-13 17:58:19
【问题描述】:

我正在尝试使用 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

【问题讨论】:

  • 你可以试试这个While rd.Read() /*Codes*/ End While

标签: vb.net mariadb mysql.data


【解决方案1】:

对rd.Read 的调用在读取数据时返回True,否则返回False。所以你需要循环直到它返回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

【讨论】:

    猜你喜欢
    • 2016-06-28
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    • 2016-09-14
    • 2020-09-13
    • 1970-01-01
    相关资源
    最近更新 更多