Click here to Skip to main content
15,607,524 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to list the return value from MySQL into excel using but my problem is only the first row is being inserted in Excel

VB.NET How to list all Column in MYSQL into 1 Column in Excel using - Stack Overflow[^]

What I have tried:

here is my code in VB.NET

Dim Type_of_Learners As String
        Dim List_TypesOfLearners_for_Today As String = "SELECT survey_at_what_blh as 'Type of Learners', COUNT(survey_at_what_blh) as COUNT
                                                        FROM daily_report 
                                                    GROUP BY survey_at_what_blh 
                                                        ORDER BY count DESC"
        da = New MySqlDataAdapter(List_TypesOfLearners_for_Today, mycon)
        dt = New DataTable()
        Type_of_Learners = dt.Rows(0)("Type of Learners")
        xlNewSheet.Cells(66, 8) = Type_of_Learners
Updated 17-Feb-21 2:04am

1 solution

Your code is doing exactly what you've told it to do - take the value from the "Type of Learners" column on the first row of the result, and insert it into cell 66,8 in your sheet.

If you want to insert data from multiple rows, then you need to loop over the rows and insert the data accordingly.
Dim rowIndex As Integer = 0
For Each row As DataRow In dt
    xlNewSheet.Cells(66 + rowIndex, 8) = row("Type of Learners")
    xlNewSheet.Cells(66 + rowIndex, 9) = row("COUNT")
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900