TX Text Control 邮件合并(一)与MS SQL Server 数据合并
我们之前提供的邮件合并功能示例使用的是XML作为数据源,在实际项目中,将MS SQL Server作为数据源的情况更为常见。不管使用什么样的数据源,其操作步骤都非常相似:我们需要循环所有的合并字段,并将这些字段与数据源中的特定列的数据进行合并。在该示例中,我们将使用DocumentServer命名空间中提供的适配器字段(MergeField类型),这些适配器字段可以用于创建/操纵特定的ApplicationField对象,而且不必手动修改ApplicationField.Parameters属性的值。
下面的代码演示了合并操作的处理过程:// loop through all fields to merge
// the text with the database content
foreach (TXTextControl.ApplicationField field in tx.ApplicationFields)
{
try
{
if (field.TypeName != "MERGEFIELD")
return;
// create a new field adapter
TXTextControl.DocumentServer.Fields.MergeField mf =
new TXTextControl.DocumentServer.Fields.MergeField(field);
if (this.customersDataSet.customers.Columns.Contains(mf.Name) == false)
continue;
// merge the text
field.Text = this.customersDataSet.customers.Rows.Index].ToString();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
运行效果:
源码:MS SQLServer + VS2010 + TX17.0
页:
[1]