- Home
- Forum
- ASP.NET Web Forms (Classic)
- Nested Mail Merge
Nested Mail Merge
Hi
I am trying to run the below example..the code gets executed but the fields are not reflecting on the word document
can you please help me
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
SIGN IN To post a reply.
1 Reply
SK
Sathish K
Syncfusion Team
December 6, 2013 01:49 PM UTC
Hi Siva,
Thank you
for your interest in Syncfusion products.
We have
prepared a sample to perform nested mail merge operation. Please refer the attached
sample and template document to know about performing mail merge and try this
in your sample. If still issue reproduces at your end then modify the sample
and provide us the modified sample to reproduce the issue at our end.
Please let
us know if you have any questions.
Regards,
Sathish
GenerateWord_Web_263c84c7.zip
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
SI siva
- Nov 28, 2013 07:39 AM UTC
- Dec 6, 2013 01:49 PM UTC