【问题标题】:VB.NET How to list all Column in MYSQL into 1 Column in Excel using vb.netVB.NET 如何使用 vb.net 将 MYSQL 中的所有列列为 Excel 中的 1 列
【发布时间】:2021-02-17 10:41:30
【问题描述】:

我正在尝试使用 vb.net 将 MySQL 的返回值列出到 excel 中,但我的问题是只有第一行被插入到 Excel 中

这是来自 MySQL 的返回查询

Types of Learners Count
Grade 1 3
Grade 2 4

这是我在 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

我应该使用数据集吗?

【问题讨论】:

  • 这是因为你在这里只选择了第一行Type_of_Learners = dt.Rows(0)("Type of Learners") 你必须循环返回数据集并填充每一行

标签: mysql excel vb.net basic


【解决方案1】:
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 
   

     

【讨论】:

  • 它显示'table'不是数据表成员的错误
  • 检查编辑的答案..我以为你在使用数据集
  • 欢迎兄弟..如果解决了您的问题,请接受答案
猜你喜欢
  • 1970-01-01
  • 2015-04-12
  • 1970-01-01
  • 2015-08-13
  • 2012-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多