TX Text Control 邮件合并(一)与MS SQL Server 数据合并

发布时间:2012/11/16 00:11 发布者:葡萄城产品团队

返回博客中心

我们之前提供的邮件合并功能示例使用的是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[dataGridView1.SelectedRows[0].Index][mf.Name].ToString();
        }
        catch (Exception exc)
        {
            MessageBox.Show(exc.Message);
        }
    }
复制代码

运行效果:


源码:MS SQLServer + VS2010 + TX17.0

tx_sql_db.zip (292.95 K, 下载次数:15)

关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网