I'm no expert on this, and need some correction :-)
I'm trying to rewrite the example Employee Report Sample to talk to my sql server database and open the result as Sample.doc.
Accompany Demo.doc as I try to print to.
But get it unfortunately will not work. Help on the way would be appreciated as I suspect I have done something wrong, either in code or in demo.doc file.
Sample.doc opened, but no data, looks exactly demo.doc
--------------------------------------------------------------------------------
Dim table As New DataTable()
Dim MyConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings.Get("xxxxxx"))
Dim SelectCommand As String = "Select TOP(5) fornamn, efternamn from medlem"
Dim MyDataAdapter As New SqlDataAdapter(SelectCommand, MyConnection)
MyDataAdapter.Fill(table)
MyDataAdapter.Dispose()
MyConnection.Close()
dataPath = Server.MapPath("~/test/Demo.doc")
Dim document As New WordDocument()
document.Open(dataPath, FormatType.Doc)
table.TableName = "medlem"
document.MailMerge.ExecuteGroup(table)
document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment)
End Sub
Attachment:
Demo_c41b718a.zip