gpt4 book ai didi

mysql - 如何将数据导出到 word 文档,而不是 SQL 查询?网络

转载 作者:行者123 更新时间:2023-11-29 00:12:45 25 4
gpt4 key购买 nike

我一直在努力解决这个问题。我编写了一个 SQL 查询来选择与特定机构有关系的某些数据。现在,当我在 MySQL Workbench 中测试它时,SQL 查询工作得很好,但是,当我尝试将该数据从 VB.NET 导出到 word 文档时,它会打印出 SQL。

下面是我的代码:

    Dim sqlAdapter As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim sqlTable As New DataTable

Dim sqlFundText As String = "select mutual_Fund_name, concat(contact_first_name,' ',contact_last_name) from mutual_fund mf, contact c, mutual_fund_has_contact mfhc, institution i, institution_has_mutual_Fund ihmf where mf.mutual_fund_id = mfhc.mutual_fund_id and c.contact_id = mfhc.contact_id and ihmf.mutual_fund_id = mf.mutual_fund_id and i.institution_id = ihmf.institution_id and i.institution_name ='" & InstitutionNameTextBox.Text & "' order by mutual_fund_name;"

With sqlCommand
.CommandText = sqlFundText
.Connection = sConnection
End With

With sqlAdapter
.SelectCommand = sqlCommand
.Fill(sqlTable)
End With

oPara9 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
With oPara9
.Range.Font.Bold = False
.Range.Text = sqlFundText
.Range.Font.Size = 10
.Format.SpaceAfter = 5
.Range.InsertParagraphAfter()
End With

结果是:

enter image description here

如您所见,它打印出 SQL 语句。

我知道这与

.Range.Text = sqlFundText

我只是不知道如何解决它。谁能指导我解决此问题的正确方法?

最佳答案

您查询的数据在 sqlTable 中。您需要从数据表中提取数据并将其添加到您的文档中,而不是 sqlFundText

在您的 With sqlAdapter ... End With block 之后,您需要执行以下操作:

Dim fundName as String
Dim contactName as String
For Each row in sqlTable.Rows
fundName = row[0].ToString()
contactName = row[1].ToString()
' Do something to put fundName and contactName into the document
Next

关于mysql - 如何将数据导出到 word 文档,而不是 SQL 查询?网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24289845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com