Hi there,
I’m a little confused on how the mail merge works with a DataSet / DataTable in C#. I have a DataSet with a DataTable in and multiple rows of data within that table, I’ve lined up the table column names to the merge field names but all i get in the process is a multiple page document without the fields being populated. I can guess that I’ve missed something but I need a little help on what exactly it is.
Thanks
Mike.
Hi
Thanks for your inquiry. Have you specified name of DataTable? You can do this using the following code.
myDataSet.Tables[0].TableName = "myTable";
Also you should use “TableStart:myTable” and "TableEnd:myTable’ field names in the template.
Please see the following link to learn more about mail merge with regions.
https://docs.aspose.com/words/net/types-of-mail-merge-operations/
Also please attach your template and code for investigating.
Best regards.
First thing I tried, Attached is my template and xml representation of the DataSet, below is the code I’m using.
//create the document
Document doc = new Document(strDocFilename);
//check that there are tables within the
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
doc.MailMerge.Execute(dt);
doc.Save(strSaveFilename);
}
Hi
Thanks for additional information. You just should use ExecuteWithRegions method. See the following code.
string strDocFilename = @"Test053\Course.doc";
string strOutDocFilename = @"Test053\out.doc";
DataSet ds = new DataSet();
ds.ReadXml(@"Test053\test.xml");
//create the document
Document doc = new Document(strDocFilename);
//check that there are tables within the
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
doc.MailMerge.ExecuteWithRegions(dt);
doc.Save(strOutDocFilename);
}
Best regards.
I tried that too, returns a single page document that is identical to the template.
Turns out i was passing in the wrong dataset, thanks for your help anyway!