tmighty
tmighty

Reputation: 11389

.NET MySQL: Print column names and values

I would like to print/debug the name of all columns and their values.

I tried something like this:

    Dim nCmd As MySqlCommand
    nCmd = New MySqlCommand("SELECT * FROM payinout WHERE inout_searcher=" & Apo(u), g_CnWebDB)

    Dim r As MySqlDataReader
    r = nCmd.ExecuteReader()
    bExists = r.HasRows

        For Each f As Field In r.fields
            Debug.Print(f.name & ": " & f.value)
        Next

... but since these members are missing, I guess I am not on the right track. Can anybody help, please?

Upvotes: 0

Views: 1566

Answers (1)

Steve
Steve

Reputation: 216243

Try with a standard loop using FieldCount and GetName method, but call Read before trying to read anything from the MySqlDataReader

    r.Read()
    For x = 0 To r.FieldCount - 1
        Debug.Print(r.GetName(x) & ": " & r(x).ToString)
    Next

Please, take note, the query used is open to Sql Injection. If this is only test code then it doesn't matter, but in production use parameterized queries.

Upvotes: 2

Related Questions