0

I am trying to get all results with the MySQL.Data Nuget because I am using MariaDB. But my Method just provides the first entry in my DB and does nothing more.

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
1
  • can you try this While rd.Read() /*Codes*/ End While Commented Aug 6, 2019 at 8:17

1 Answer 1

1

The call to rd.Read returns True when data is read, and False otherwise. So you need to loop until it 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.