@alexey.noskov : I am attaching a spreadsheet with sample data. This is a snippet of code that runs in my application:
DataSet dsMasterPetition = GetMasterPetitionKML(FileNum.ToString(), TaxYear, RespondentKey, Suffix);
if (dsMasterPetition.Tables[0].Rows.Count > 0)
{
WordViewModel_MasterPetition MailMergeData = new WordViewModel_MasterPetition();
MailMergeData = GetMasterPetitionHeaderData(FileNum, Suffix, RespondentKey, TaxYear, IndexNo, ReturnDate, PetitionDate);
dsMasterPetition.Tables[0].TableName = "MasterPetition";
dsMasterPetition.Tables[1].TableName = "MasterPetitionFile";
dsMasterPetition.Relations.Add(dsMasterPetition.Tables[1].Columns["FileNum"], dsMasterPetition.Tables[0].Columns["FileNum"]);
string masterFilePath = GenericHelper.FetchLetterTemplates("MasterPetition");
MailMergeData.CaptionRespondent = "THE ASSESSOR and THE BOARD OF ASSESSMENT REVIEW OF " + MailMergeData.CaptionRespondent;
try
{
object oMPQRCode = dsMasterPetition.Tables[0].Rows[0].ItemArray[27];
string FileAndSuffix = "";
FileAndSuffix = FileNum > 0 ? "FILE: " + FileNum.ToString() + "-" + Suffix : "";
Aspose.Words.Document masterTemplate = new Aspose.Words.Document(masterFilePath);
masterTemplate.FieldOptions.BarcodeGenerator = new CustomBarcodeGenerator();
masterTemplate.MailMerge.CleanupOptions = Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs;
masterTemplate.MailMerge.ExecuteWithRegions(dsMasterPetition);
The dsMasterPetition calls a function called GetMasterPetitionKML. This is the code that exeutes in GetMasterPetitionKML:
public DataSet GetMasterPetitionKML(string fileNum, string taxYear, int Respondent, string Suffix)
{
string sConnectionString = ConfigurationManager.ConnectionStrings["TaxCertConnectionString"].ToString();
DataSet ds = new DataSet();
string sFirmName = GenericHelper.GetFirmName();
using (SqlConnection conn = new SqlConnection(sConnectionString))
{
if (Respondent > 0)
{
using (SqlCommand scCommand = new SqlCommand("p_get_Master_Petition_ByRespKML", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(scCommand))
{
scCommand.CommandType = CommandType.StoredProcedure;
scCommand.Parameters.AddWithValue("@RespondentKey", Respondent);
scCommand.Parameters.AddWithValue("@tax_year", taxYear);
scCommand.Parameters.AddWithValue("@barcode_ty", "MasterPetition");
scCommand.Parameters.AddWithValue("@user", HttpContext.Current.User.Identity.Name);
scCommand.Parameters.AddWithValue("@firmName", sFirmName);
try
{
da.Fill(ds);
}
catch (Exception ex)
{
throw;
}
}
}
}
else
{
using (SqlCommand scCommand = new SqlCommand("p_get_Master_PetitionKML", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(scCommand))
{
scCommand.CommandType = CommandType.StoredProcedure;
scCommand.Parameters.AddWithValue("@FileNum", fileNum);
scCommand.Parameters.AddWithValue("@tax_year", taxYear);
scCommand.Parameters.AddWithValue("@barcode_ty", "TestMasterPetition");
scCommand.Parameters.AddWithValue("@user", HttpContext.Current.User.Identity.Name);
scCommand.Parameters.AddWithValue("@firmName", sFirmName);
scCommand.Parameters.AddWithValue("@Suffix", Suffix);
da.Fill(ds);
}
}
}
}
return ds;
}
In my senario, Respondent = 78. The stored procedure returns 2 tables of data. The data that was returned is what you will find in the spreadsheet.
If there is anything else you need, please let me know.
Again, thank you for your assisstance.
ASPOSE sample data.zip (14.5 KB)