我一直很难弄清楚这一点。我编写了一个 SQL 查询来选择与特定机构有关系的某些数据。现在 SQL 查询工作得非常好,因为我在 MySQL Workbench 中对其进行了测试,但是,当我尝试将 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
我只是不知道如何解决它。任何人都可以指导我解决这个问题的正确方法吗?