Free Support Forum -

Merge fields with multiple regions

Dear support,

I have been using Aspose Word to convert into PDF.

Now I need to 2 tables in the same doc. I assumed that I can create the Merge fields one more time by giving the TableStart and TableEnd fields again. In the code I filled another Dataset and put another ExecuteWithRegions again. But I get an error saying that the table doesnot exist in the Dataset. The following is the code and the commented portion is the second Region. (removed SQL statement to reduce the lines. rgds/

Dim strSQL

Dim myCommand As OracleDataAdapter

Dim DS As DataSet

Dim doc As New Document(Request.MapPath(Request.ApplicationPath) & "\QoutationSamples\")

strSQL = " ..."

myCommand = New OracleDataAdapter(strSQL, myConnection)

DS = New DataSet()

myCommand.Fill(DS, "LCLGUIDE")

If DS.Tables("LCLGUIDE").Rows.Count > 0 Then


End If



' ---- second region


'strSQL = "...."

'myCommand.Fill(DS, "LCLGUIDEPOINTS")

'If DS.Tables("LCLGUIDEPOINTS").Rows.Count > 0 Then

' doc.MailMerge.ExecuteWithRegions(DS)

'End If


' ---- second region

Please attach your template document. I will check what the problem is.

Dear Vladmir,

Pl find attached. In principle is it possible to use multiple Regions?



attached again…

It seems that when you call ExecuteWithRegions second time - it searches for "LCLGUIDE" table first as the mergefields for this table still exist in the document. When it is not found in the dataset Aspose.Words breaks.

Try to fill dataset with both tables and call ExecuteWithRegions only once.

Dear Vladmir,

Thanx for the help. While I check this I have another issue for you. In the same Word file I sent you if an image is placed in the Header, it is ignored in the PDF. Could pl check on this. I am enclosing the file again with the image in the header.



From what I see the image is not ignored but rather misalligned. It is positioned inline in your template but it is better to set it floating with explicit positioning to avoid positioning problems.

I am sending the corrected template along with PDF made from it.

Also please make sure that you are using the latest versions of Aspose libraries.

I am using Aspose Word Aspose PDF

I saw that there is an update for Aspose Word to Aspose Words. Do I need to do it or any other update?



Yes, it is always a good idea to update to the latest version. Please contact Aspose.Purchase to find out how to do it.

Dear Vladimir,

I tried but now none of the two tables are shown. No error but the placeholders are only shown. I am using 2 Dataadapters to fill into the same dataset. Here's my code and attched is the word and pdf. Thanx in advance

Dim strSQL1

Dim strSQl2

Dim myCommand1 As OracleDataAdapter

Dim myCommand2 As OracleDataAdapter

Dim DS As DataSet

Dim doc As New Document(Request.MapPath(Request.ApplicationPath) & "\QoutationSamples\")

strSQL1 = "..."


strSQl2 += " .."

myCommand2 = New OracleDataAdapter(strSQl2, myConnection)

DS = New DataSet()

myCommand2.Fill(DS, "LCLGUIDEPOINTS")


myCommand1 = New OracleDataAdapter(strSQL1, myConnection)

myCommand1.Fill(DS, "LCLGUIDE")

If DS.Tables("LCLGUIDE").Rows.Count > 0 Then


End If

I have tested MailMerge of your template document with the following code:

string filename = Application.StartupPath + @"\Brief\";

Document doc = new Document(Application.StartupPath + @"\Brief\");

string pol = "POL";

string direct = "DIRECT";

string pod = "POD";

DataTable table1 = new DataTable("LCLGUIDE");




for(int i = 0; i<10; i++)


DataRow row1 = table1.NewRow();


row1[0] = pol + i;

row1[1] = direct + i;

row1[2] = pod + i;


DataTable table2 = new DataTable("LCLGUIDEPOINTS");



for(int i = 0; i<10; i++)


DataRow row2 = table2.NewRow();


row2[0] = pol + i;

row2[1] = pod + i;


DataSet ds = new DataSet();




doc.Save(Application.StartupPath + @"\Brief\LCL_aftermerge.doc");

And it works ok.

Please check the correctness of the data in the dataset after filling it. You can use debug mode and quick watch command for that purpose.