0

I'm trying to list the return value from MySQL into excel using vb.net but my problem is only the first row is being inserted in Excel

Here is the return query from MySQL

Types of Learners Count
Grade 1 3
Grade 2 4

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()
        da.Fill(dt)
        Type_of_Learners = dt.Rows(0)("Type of Learners")
        xlNewSheet.Cells(66, 8) = Type_of_Learners

Should I use data set?

1
  • this is because you just select first row here Type_of_Learners = dt.Rows(0)("Type of Learners") You have to loop with return dataset and fill each row Commented Feb 18, 2021 at 4:08

1 Answer 1

2
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()
        da.Fill(dt)
       

dim i_rowIndex as integer = 66 

for each dr as datarow in dt.rows 
  Type_of_Learners = dr("Type of Learners").tostring.trim
  xlNewSheet.Cells(i_rowIndex , 8) = Type_of_Learners
  i_rowIndex += 1
next 
   

     

Sign up to request clarification or add additional context in comments.

3 Comments

it showing a error that 'table' is not a member of datatable
check edited answer .. I thought you were use dataset
welcome bro .. Please Accept answer if it solved your problem

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.