I am trying to run the below example..the code gets executed but the fields are not reflecting on the word document
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
dataPath = Server.MapPath("")
Dim document As WordDocument = New WordDocument(Path.Combine(dataPath, "Merge.docx"), FormatType.Docx)
Dim connectionstring As String = ConfigurationManager.ConnectionStrings("sivaConnectionString").ConnectionString
Dim conn As SqlConnection = New SqlConnection(connectionstring)
conn.Open()
Dim ds As New DataSet()
Dim table As New DataTable()
Dim adapter As New SqlDataAdapter("Select * From Employees ", conn)
adapter.Fill(table)
table.TableName = "Employees"
ds.Tables.Add(table)
adapter.Dispose()
table1 = New DataTable()
adapter = New SqlDataAdapter("Select DISTINCT TOP 2 Employees.EmployeeID, Customers.CustomerID,Customers.CompanyName, Customers.ContactName, Customers.Address, Customers.City, Customers.Country FROM ((Orders INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID) INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)", conn)
adapter.Fill(table1)
table.TableName = "Customers"
ds.Tables.Add(table1)
adapter.Dispose()
table2 = New DataTable()
adapter = New SqlDataAdapter("Select DISTINCT TOP 2 OrderID, OrderDate, RequiredDate, ShippedDate FROM Orders", conn)
adapter.Fill(table2)
table.TableName = "Orders"
ds.Tables.Add(table2)
adapter.Dispose()
Dim commands As ArrayList = New ArrayList()
Dim entry As DictionaryEntry = New DictionaryEntry("Employees", String.Empty)
commands.Add(entry)
entry = New DictionaryEntry("Customers", "Employees.EmployeeID = %Employees.EmployeeID%")
commands.Add(entry)
entry = New DictionaryEntry("Orders", "Orders.CustomerID = '%Customers.CustomerID%' AND Orders.EmployeeID = %Employees.EmployeeID%")
commands.Add(entry)
document.MailMerge.RemoveEmptyParagraphs = True
document.MailMerge.ExecuteNestedGroup(ds, commands)
If (rdButtonWord97To2003.Checked) Then
document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment)
ElseIf (rdButtonWord2007.Checked) Then
document.Save("Sample.docx", FormatType.Word2007, Response, HttpContentDisposition.Attachment)
ElseIf (rdButtonWord2010.Checked) Then
document.Save("Sample.docx", FormatType.Word2010, Response, HttpContentDisposition.Attachment)
ElseIf (rdButtonWord2013.Checked) Then
document.Save("Sample.docx", FormatType.Word2013, Response, HttpContentDisposition.Attachment)
End If
End Sub