We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Nested Mail Merge

Thread ID:

Created:

Updated:

Platform:

Replies:

114627 Nov 28,2013 07:39 AM UTC Dec 6,2013 01:49 PM UTC ASP.NET Web Forms (Classic) 1
loading
Tags: DocIO
siva
Asked On November 28, 2013 07:39 AM UTC

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

Sathish K [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;