作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在努力解决这个问题。我编写了一个 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
结果是:
如您所见,它打印出 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/
我是一名优秀的程序员,十分优秀!